当我尝试在 Tomcat 上部署我的应用程序时出现以下错误。
04-Sep-2013 17:59:29.424 SEVERE [AsyncFileHandlerWriter-1626573634] org.apache.catalina.core.StandardContext.startInternal Error during ServletContainerInitializer processing
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:165)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5370)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/springframework/instrument/classloading/tomcat/TomcatInstrumentableClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:299)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at org.springframework.web.context.AbstractContextLoaderInitializer.<init>(AbstractContextLoaderInitializer.java:42)
at org.springframework.web.servlet.support.AbstractDispatcherServletInitializer.<init>(AbstractDispatcherServletInitializer.java:58)
at org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer.<init>(AbstractAnnotationConfigDispatcherServletInitializer.java:40)
at com.bravofly.wfcobrand.configuration.web.ServletConfiguration.<init>(ServletConfiguration.java:10)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:162)
... 13 more
我已经发现问题出在 lib 目录中的库中:slf4j-api-1.5.11.jar。
放在那里org.slf4j:slf4j-api:1.7.1
解决org.slf4j:jcl-over-slf4j:1.7.1
了我的问题。
我想知道是否可以在我的应用程序中做一些事情来解决这个问题。我正在使用 gradle,所以我放了:
compile ... other dependencies
"org.slf4j:slf4j-api:1.7.1",
"org.slf4j:jcl-over-slf4j:1.7.1"
但这并没有解决问题。有没有办法优先考虑我的构建文件中定义的库?