天天看点

mongodb的jar包日志文件和webservice的AxisServlet日志文件冲突

昨天发布工程遇到了一个棘手的问题,localhost.log报错信息如下: org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory

at org.apache.commons.discovery.tools.DiscoverClass.find(DiscoverClass.java:404)

at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)

16-Feb-2017 20:34:16.306 INFO [http-nio-8080-exec-493] org.apache.catalina.core.ApplicationContext.log Marking servlet AxisServlet as unavailable

16-Feb-2017 20:34:16.307 SEVERE [http-nio-8080-exec-493] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet AxisServlet

 java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis.transport.http.AxisServlet

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

catalina.out的报错信息如下:22-Apr-2016 10:49:15.785 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [253] milliseconds.

[2016-04-22 10:49:18,465]-INFO  (CommonsLogger.java:46)|Parsing configuration file [struts-default.xml]

[2016-04-22 10:49:18,744]-INFO  (CommonsLogger.java:46)|Parsing configuration file [struts-plugin.xml]

[2016-04-22 10:49:18,762]-INFO  (CommonsLogger.java:46)|Parsing configuration file [struts.xml]

[2016-04-22 10:49:18,772]-INFO  (CommonsLogger.java:46)|Choosing bean (struts) for (com.opensymphony.xwork2.ObjectFactory)

[2016-04-22 10:49:18,774]-INFO  (CommonsLogger.java:46)|Choosing bean (struts) for (com.opensymphony.xwork2.factory.ActionFactory)

[2016-04-22 10:49:18,775]-INFO  (CommonsLogger.java:46)|Choosing bean (struts) for (com.opensymphony.xwork2.factory.ResultFactory)

[2016-04-22 10:49:18,776]-INFO  (CommonsLogger.java:46)|Choosing bean (struts) for (com.opensymphony.xwork2.factory.ConverterFactory)

纠结了一天之后,发现是AxisServlet的日志文件是org.apache.commons.logging.Log包下的,由于这次上线了mongodb功能,MongoTemplate.class用的 import org.slf4j.Logger;

import org.slf4j.LoggerFactory  slf4j的日志。打包过程中commons-logging-1.2.jar,slf4j-api-1.77.jar,jcl-over-slf4j-1.7.21.jar同时存在。导致org.apache.commons.logging.LogFactory 冲突。  jcl-over-slf4j-1.7.21.jar的功能就是用来替代commons-logging系列包的。所以删除commons-logging-1.2系统的jar包,重启系统解决问题。