jboss log4j和工程log4j冲突

近期项目过程中,出现了一个问题,日志不能记录到jboss的server.log中。

这个问题导致程序的调试很困难。开始看jboss启动的debug信息,发现一个error信息。

ERROR "org.jboss.logging.util.OnlyOnceErrorHan
dler" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@f62373]

查找了jboss的论坛,原来是在自己工程的WEB-INF/lib目录下多了log4j.jar,删除此jar。然后从别的位置引入工程编译通过后,重新发布到jboss中,测试记录日志。ok成功了。

开始看到的一个说法是错误的:修改%JBOSS-HOME/server//default/deploy/jboss-web.deployer/META-INF/jboss-service.xml

<attribute name="Java2ClassLoadingCompliance">true</attribute>
<attribute name="UseJBossWebLoader">true</attribute>
修改之后记录日志是可以了,因为相同的jar只加载了一次,但是如果存在2个struts的工程在jboss下,
就会出现struts.xml的加载错误。
Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/D:/eclipseCommunity/workspaceCommunity/upload/webapp/WEB-INF/lib/struts2-core-j4-2.0.9.jar!/struts-default.xml:8:72
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:208)
        at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
        at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:131)
        at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
        at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
        at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:201)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:223)
        at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:304)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:77)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3600)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4193)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
        at org.apache.catalina.core.StandardService.start(StandardService.java:450)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - file:/D:/eclipseCommunity/workspaceCommunity/upload/webapp/WEB-INF/classes/struts-default.xml:8:72 - bean - jar:file:/D:/eclipseCommunity/workspaceCommunity/upload/webapp/WEB-INF/lib/struts2-core-j4-2.0.9.jar!/struts-default.xml:8:72
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:193)
        ... 24 more


把上面2个值改为false就不会出现该问题了。
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页