哦,生产环境可以用standalone.sh启动JBoss7.1.1 AS吗? 通常我们使用init脚本启动它,然后在jboss-cli.sh的帮助下部署WAR。 但是这种方法不允许创建日志文件。
log4j.appender.A1.File=../server/default/log/Mylog.log
当我使用standalone.sh启动服务器时,会成功创建日志文件。
但是,当我开始使用服务jboss start&然后使用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>
如果我使用standalone.sh启动JBoss7.1.1.FINAL,这段代码可以正常工作,但如果我使用service jboss start并使用部署warname.war
部署war与jboss-cli.sh,则会出现此错误请帮忙。
答案 0 :(得分:0)
它说
java.io.FileNotFoundException: ../server/default/log/Mylog.log
因此,当您以“service jboss start”开头时,当前目录会有所不同。尝试将JBOSS_HOME添加到jboss-as.conf或安装JBoss JBOSS_HOME =的/ usr /共享/ JBoss的-作为