websphere下log4j不起作用的问题

最近在做项目时,应用程序服务器从webLogic换到websphere7后,项目中配置的log4j.xml 文件竟然不起作用了,日志文件一个都没有打出来。

经过查证,原来是websphere的日志配置优先级要大于工程中的log4j的配置,都was7了还存在这个问题,不知道IBM有没有想过啥时候能彻底解决一下这个毛病。

下面是从网络上看到的一个解决方法,觉得很有效,在这里和大家分享一下。


1、新建一个 commons-logging.properties配置文件,文件内容为: 

priority=1

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

2、将写好配置的commons-logging.properties

  放到 /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/properties目录下


在windows上测试时,把上述文件放到websphere后,启动之后进入控制台会报有关servlet的错误。

com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.exception.RuntimeError: java.lang.RuntimeException: java.lang.ExceptionInInitializerError
	at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:316)
	at com.ibm.ws.runtime.component.ContainerHelper.startComponents(ContainerHelper.java:538)
	at com.ibm.ws.runtime.component.ContainerImpl.startComponents(ContainerImpl.java:627)
	at com.ibm.ws.runtime.component.ContainerImpl.start(ContainerImpl.java:618)
	at com.ibm.ws.runtime.component.ApplicationServerImpl.start(ApplicationServerImpl.java:227)
	at com.ibm.ws.runtime.component.ContainerHelper.startComponents(ContainerHelper.java:538)
	at com.ibm.ws.runtime.component.ContainerImpl.startComponents(ContainerImpl.java:627)
	at com.ibm.ws.runtime.component.ContainerImpl.start(ContainerImpl.java:618)
	at com.ibm.ws.runtime.component.ServerImpl.start(ServerImpl.java:503)
	at com.ibm.ws.runtime.WsServerImpl.bootServerContainer(WsServerImpl.java:298)
	at com.ibm.ws.runtime.WsServerImpl.start(WsServerImpl.java:214)
	at com.ibm.ws.runtime.WsServerImpl.main(WsServerImpl.java:666)
	at com.ibm.ws.runtime.WsServer.main(WsServer.java:59)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:600)
	at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:213)
	at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:93)
	at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:74)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:600)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:340)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:282)
	at org.eclipse.core.launcher.Main.run(Main.java:981)
	at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:340)
	at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:110)
Caused by: com.ibm.ws.exception.RuntimeError: java.lang.RuntimeException: java.lang.ExceptionInInitializerError
	at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:748)
	at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:953)
	at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:349)
	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
Caused by: java.lang.RuntimeException: java.lang.ExceptionInInitializerError
	at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:988)
	at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:725)
	... 3 more
Caused by: java.lang.ExceptionInInitializerError
	at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
	at com.ibm.ws.websvcs.component.WASAxis2ComponentImpl.initComponent(WASAxis2ComponentImpl.java:543)
	at com.ibm.ws.websvcs.component.WASAxis2ComponentImpl.metaDataCreated(WASAxis2ComponentImpl.java:768)
	at com.ibm.ws.runtime.component.MetaDataMgrImpl.fireMetaDataCreated(MetaDataMgrImpl.java:190)
	at com.ibm.ws.runtime.component.MetaDataMgrImpl.createMetaData(MetaDataMgrImpl.java:343)
	at com.ibm.ws.runtime.component.MetaDataMgrImpl.createMetaDataFromFactories(MetaDataMgrImpl.java:174)
	at com.ibm.ws.runtime.component.MetaDataMgrImpl.createMetaData(MetaDataMgrImpl.java:308)
	at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:924)
	... 4 more
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: java.lang.ClassNotFoundException: org.apache.commons.logging.impl.Log4JLogger
	at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:532)
	at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:272)
	at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:246)
	at org.apache.commons.logging.LogFactory$2.run(LogFactory.java:424)
	at java.security.AccessController.doPrivileged(AccessController.java:251)
	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:415)
	at org.apache.axis2.jaxws.message.factory.ClassFinderFactory.<clinit>(ClassFinderFactory.java:28)
	at java.lang.J9VMInternals.initializeImpl(Native Method)
	at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
	... 11 more
Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.ClassNotFoundException: org.apache.commons.logging.impl.Log4JLogger
	at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:416)
	at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:525)
	... 19 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.impl.Log4JLogger
	at java.lang.Class.forNameImpl(Native Method)
	at java.lang.Class.forName(Class.java:136)
	at org.apache.commons.logging.impl.LogFactoryImpl$1.run(LogFactoryImpl.java:466)
	at java.security.AccessController.doPrivileged(AccessController.java:202)
	at org.apache.commons.logging.impl.LogFactoryImpl.loadClass(LogFactoryImpl.java:454)
	at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:406)
	... 20 more


如果出现了错误,可以把上述文件内容简化为:

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

只要这一句话就够了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值