解决jboss和log4j冲突的最理想配置如下:
1.配置$JBOSS-HOME/server/default/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml
文件里的Java2ClassLoadingCompliance及UseJBossWebLoader为false,
如果你的应用下存在WEB-INF/jboss-web.xml,则里面的java2ClassLoadingCompliance及java2ParentDelegaton属性也都设置成false。
2.配置$JBOSS-HOME/server/default/jboss-service.xml中的org.jboss.logging.Log4jService的设置中加个属性:<attribute name="CatchSystemOut">false</attribute>即可
如下:
<mbean code="org.jboss.logging.Log4jService" name="jboss.system:type=Log4jService,service=Logging">
<attribute name="ConfigurationURL">resource:log4j.xml</attribute>
<attribute name="CatchSystemOut">false</attribute>
<attribute name="Log4jQuietMode">true</attribute>
</mbean>
3.建立一个用于初始化的 InitServlet ,在init方法指定log4j读取我们应用下的的log4j.properties文件,代码如:
public void init(ServletConfig config) throws ServletException {
PropertyConfigurator.configure(config.getServletContext().getRealPath("/")
+ "WEB-INF/classes/log4j.properties");
}
然后在 web.xml 配置这个 Servlet 的初始化参数(声明 log4j.properties 的位置)和启动优先级:
<servlet>
<servlet-name>InitServlet</servlet-name>
<servlet-class>InitServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
4.把jboss的jboss-common.jar($JBOSS-HOME/lib目录下)复制到你的应用/WEB-INF/lib目录下。
通过这样的配置后,webapp的log4j和jboss的log4j将相互隔离互不影响,在jboss.4.0.5下测试通过,并做的总结。