2
哦,生產環境,我們可以用standalone.sh啓動JBoss7.1.1 AS嗎? 通常我們用init腳本啓動它,然後在jboss-cli.sh的幫助下部署WAR。 但是這種方法不會讓記錄文件創建。JBoss 7多log4j配置使用彈簧配置文件
log4j.appender.A1.File=../server/default/log/Mylog.log
當我用standalone.sh啓動服務器時,日誌文件已成功創建。
但是當我用服務jboss啓動它時,啓動&然後用jboss-cli.sh部署它 我得到這個錯誤。
12:00:38,996 ERROR [stderr] (MSC service thread 1-3) log4j:ERROR setFile(null,true) call failed.
12:00:38,997 ERROR [stderr] (MSC service thread 1-3) java.io.FileNotFoundException: ../server/default/log/Mylog.log (No such file or directory)
12:00:38,998 ERROR [stderr] (MSC service thread 1-3) at java.io.FileOutputStream.open(Native Method)
12:00:38,998 ERROR [stderr] (MSC service thread 1-3) at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
12:00:38,999 ERROR [stderr] (MSC service thread 1-3) at java.io.FileOutputStream.<init>(FileOutputStream.java:136)
12:00:38,999 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
12:00:39,000 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207)
12:00:39,000 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
12:00:39,000 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
12:00:39,000 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
12:00:39,001 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
12:00:39,001 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:842)
12:00:39,001 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:768)
12:00:39,002 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:648)
12:00:39,002 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:514)
12:00:39,002 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:580)
12:00:39,003 ERROR [stderr] (MSC service thread 1-3) at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:415)
12:00:39,003 ERROR [stderr] (MSC service thread 1-3) at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:72)
12:00:39,003 ERROR [stderr] (MSC service thread 1-3) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12:00:39,004 ERROR [stderr] (MSC service thread 1-3) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
12:00:39,004 ERROR [stderr] (MSC service thread 1-3) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
12:00:39,004 ERROR [stderr] (MSC service thread 1-3) at java.lang.reflect.Method.invoke(Method.java:606)
12:00:39,005 ERROR [stderr] (MSC service thread 1-3) at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
12:00:39,005 ERROR [stderr] (MSC service thread 1-3) at org.springframework.beans.factory.config.MethodInvokingFactoryBean.doInvok
我已經加入JBoss部署結構也
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
<!-- <jboss-deployment-structure> <deployment> <exclusions> <module name="org.apache.log4j"
/> </exclusions> </deployment> <sub-deployment name="takaful.war"> <exclusions>
<module name="org.apache.log4j" /> </exclusions> </sub-deployment> <sub-deployment
name="takaful-0.0.1-SNAPSHOT.jar"> <exclusions> <module name="org.apache.log4j"
/> </exclusions> </sub-deployment> </jboss-deployment-structure> -->
和最後我的Spring bean來初始化log4j的。
<beans profile="a">
<bean id="logb"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>${loc}/${log4j.properties.location}</value>
</list>
</property>
</bean>
</beans>
<beans profile="b">
<bean id="logb"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>${loc}/${log4j.properties.location2}</value>
</list>
</property>
</bean>
</beans>
<beans profile="c">
<bean id="logb"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>${loc}/${log4j.properties.location3}</value>
</list>
</property>
</bean>
</beans>
此代碼的工作完美,如果我開始JBoss7.1.1.FINAL與standalone.sh但如果我使用JBoss的服務開始和部署warname.war部署與jboss-cli.sh戰爭給這個錯誤
請幫忙。