Tomcat 上的部署:解析方法 "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" 时违反约束
Deployment on Tomcat: Constraint violation when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;"
我正在 Tomcat 8.0.22 上部署 Shibboleth IdP 3.1.1,但我收到此错误:
SEVERE [http-nio-8080-exec-13] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.BeanInstantiationException: Failed to instantiate [net.shibboleth.ext.spring.context.DeferPlaceholderFileSystemXmlWebApplicationContext]: Constructor threw exception; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:360)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1293)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:673)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:221)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
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/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) 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:336)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:284)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:305)
at net.shibboleth.ext.spring.context.FileSystemXmlWebApplicationContext.<init>(FileSystemXmlWebApplicationContext.java:35)
at net.shibboleth.ext.spring.context.DeferPlaceholderFileSystemXmlWebApplicationContext.<init>(DeferPlaceholderFileSystemXmlWebApplicationContext.java:33)
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 org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 39 more
关于java版本的信息:
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
我放入 $CATALINA_HOME/lib
罐子:slf4j-api-1.7.12.jar
、slf4j-log4j12-1.7.12.jar
和 nlog4j-1.2.14.jar
但这并不能解决问题。我尝试将 org.slf4j
作为 Maven 的依赖项,但也不起作用。
有没有办法解决这个异常?感谢您的任何建议。
这意味着您的 war
中可能有两个不同的 slf4j 库
org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature
您可以使用该命令查找应用程序中注入的 slf4j 依赖项。
mvn dependency:tree -Dverbose -Dincludes=commons-collections
resolving conflicts using the dependency tree
并在 Maven 中排除依赖项:
<dependency>
[...]
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
<dependency>
您也可以解压缩 war 文件并在 WEB-INF/lib/ 中查找您拥有的不同版本的 slf4j。
问题已解决。我使用 mvn dependency:tree 查看依赖项:
ricardo@ricardo-SW6H:~/Documents/teste_rabbit/java-identity-provider/branches/3.1/idp-war$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Shibboleth IdP :: War
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] net.shibboleth.idp:idp-war:war:3.1.1
[INFO] +- org.slf4j:slf4j-api:jar:1.7.10:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.2:runtime
[INFO] | \- ch.qos.logback:logback-core:jar:1.1.2:runtime
[INFO] +- org.testng:testng:jar:6.8.8:compile
[INFO] | \- com.beust:jcommander:jar:1.47:compile (version managed from 1.27)
[INFO] +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.10:compile
[INFO] +- org.slf4j:jul-to-slf4j:jar:1.7.10:compile
[INFO] +- xmlunit:xmlunit:jar:1.5:compile
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.7.10:compile
[INFO] +- edu.vt.middleware:idp-memcached-storage:jar:1.0-SNAPSHOT:compile
[INFO] | +- net.spy:spymemcached:jar:2.11.4:compile
[INFO] | \- org.cryptacular:cryptacular:jar:1.0:compile
[INFO] +- net.shibboleth.idp:idp-attribute-api:jar:3.1.1:compile
[INFO] | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- net.shibboleth.idp:idp-attribute-filter-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-attribute-filter-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-attribute-filter-spring:jar:3.1.1:compile
[INFO] | +- org.springframework:spring-beans:jar:4.1.5.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:4.1.5.RELEASE:compile
[INFO] | \- org.springframework:spring-context:jar:4.1.5.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.1.5.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | \- org.springframework:spring-expression:jar:4.1.5.RELEASE:compile (version managed from 4.0.6.RELEASE)
[INFO] +- net.shibboleth.idp:idp-attribute-resolver-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-attribute-resolver-impl:jar:3.1.1:compile
[INFO] | +- org.apache.velocity:velocity:jar:1.7:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | \- commons-lang:commons-lang:jar:2.4:compile
[INFO] | +- joda-time:joda-time:jar:2.7:compile
[INFO] | +- org.ldaptive:ldaptive:jar:1.0.6:compile
[INFO] | \- javax.json:javax.json-api:jar:1.0:compile
[INFO] +- net.shibboleth.idp:idp-attribute-resolver-spring:jar:3.1.1:compile
[INFO] | \- com.mchange:c3p0:jar:0.9.2.1:compile
[INFO] | \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
[INFO] +- net.shibboleth.idp:idp-authn-api:jar:3.1.1:compile
[INFO] | \- org.glassfish:javax.json:jar:1.0.4:runtime
[INFO] +- net.shibboleth.idp:idp-authn-impl:jar:3.1.1:compile
[INFO] | \- org.springframework.webflow:spring-webflow:jar:2.4.1.RELEASE:compile
[INFO] | +- opensymphony:ognl:jar:2.6.11:compile
[INFO] | +- org.springframework.webflow:spring-binding:jar:2.4.1.RELEASE:compile
[INFO] | +- org.springframework.webflow:spring-js:jar:2.4.1.RELEASE:compile
[INFO] | | \- org.springframework.webflow:spring-js-resources:jar:2.4.1.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.1.5.RELEASE:compile
[INFO] +- net.shibboleth.idp:idp-consent:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-cas-api:jar:3.1.1:compile
[INFO] | \- org.springframework:spring-web:jar:4.1.5.RELEASE:compile
[INFO] +- net.shibboleth.idp:idp-cas-impl:jar:3.1.1:compile
[INFO] | \- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] | \- org.apache.httpcomponents:httpcore:jar:4.3.3:compile
[INFO] +- net.shibboleth.idp:idp-core:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-profile-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-profile-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-profile-spring:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-saml-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-saml-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-schema:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-session-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-session-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-ui:jar:3.1.1:compile
[INFO] +- net.shibboleth.ext:spring-extensions:jar:5.1.1:compile
[INFO] | \- org.apache.httpcomponents:httpclient-cache:jar:4.3.6:compile
[INFO] +- org.opensaml:opensaml-core:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-messaging-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-messaging-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-profile-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-profile-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-saml-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-saml-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-security-api:jar:3.1.1:compile
[INFO] | +- org.apache.santuario:xmlsec:jar:2.0.3:compile
[INFO] | | \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
[INFO] | | +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] | | \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] | \- org.bouncycastle:bcprov-jdk15on:jar:1.51:compile
[INFO] +- org.opensaml:opensaml-security-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-soap-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-soap-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-storage-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-storage-impl:jar:3.1.1:compile
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:4.3.5.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] | | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | | +- org.hibernate:hibernate-core:jar:4.3.5.Final:compile
[INFO] | | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | | \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile
[INFO] | | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] | | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | \- org.springframework:spring-orm:jar:4.1.5.RELEASE:compile
[INFO] | +- org.springframework:spring-jdbc:jar:4.1.5.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:4.1.5.RELEASE:compile
[INFO] +- org.opensaml:opensaml-xmlsec-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-xmlsec-impl:jar:3.1.1:compile
[INFO] +- com.google.code.findbugs:jsr305:jar:3.0.0:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- org.codehaus.janino:janino:jar:2.7.8:compile
[INFO] | \- org.codehaus.janino:commons-compiler:jar:2.7.8:compile
[INFO] +- net.shibboleth.utilities:java-support:jar:7.1.1:compile
[INFO] +- javax.mail:mail:jar:1.4.7:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.5.RELEASE:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:provided
[INFO] +- org.springframework:spring-test:jar:4.1.5.RELEASE:test
[INFO] \- net.shibboleth.utilities:java-support:test-jar:tests:7.1.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Sun Jul 05 21:56:37 CEST 2015
[INFO] Final Memory: 39M/345M
[INFO] ------------------------------------------------------------------------
使用这个结果,我将这个依赖项放在 pom.xml 中:
<!-- language:lang-xml -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.10</version>
</dependency>
现在问题解决了。非常感谢您的帮助。
这个问题可能是因为servlet容器中有jar(Ex Tomcat)。
例如:
- 有人在 tomcat 的库中保留了一些库(在本例中为 slf4j)。
- 您向 tomcat 部署了一个新项目。
- 在你的新项目中,你的一些依赖项依赖于那个库。
- 然后在你的新项目Tomcat和WAR中复制了同一个jar
然后你得到这样的错误信息。
解决这个问题的办法就是用"scope"说是提供了
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
<scope>provided</scope>
</dependency>
通过这样做,WAR 文件将不包含该依赖项。
如果您使用的是spring-boot-starter-web-1.5.1.RELEASE.jar,那么您需要排除jul -to-slf4j-1.7.22.jar,jcl-over-slf4j-1.7.22.jar.这两个jar有冲突slf4j-api.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>
WEB-INF/lib/jcl-over-slf4j-1.7.22.jar,WEB-INF/lib/jul-to-slf4j-1.7.22.jar
</packagingExcludes>
</configuration>
</plugin>
我正在 Tomcat 8.0.22 上部署 Shibboleth IdP 3.1.1,但我收到此错误:
SEVERE [http-nio-8080-exec-13] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.BeanInstantiationException: Failed to instantiate [net.shibboleth.ext.spring.context.DeferPlaceholderFileSystemXmlWebApplicationContext]: Constructor threw exception; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:360)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1293)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:673)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:221)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
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/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of java/net/URLClassLoader) 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:336)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:284)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:305)
at net.shibboleth.ext.spring.context.FileSystemXmlWebApplicationContext.<init>(FileSystemXmlWebApplicationContext.java:35)
at net.shibboleth.ext.spring.context.DeferPlaceholderFileSystemXmlWebApplicationContext.<init>(DeferPlaceholderFileSystemXmlWebApplicationContext.java:33)
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 org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 39 more
关于java版本的信息:
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
我放入 $CATALINA_HOME/lib
罐子:slf4j-api-1.7.12.jar
、slf4j-log4j12-1.7.12.jar
和 nlog4j-1.2.14.jar
但这并不能解决问题。我尝试将 org.slf4j
作为 Maven 的依赖项,但也不起作用。
有没有办法解决这个异常?感谢您的任何建议。
这意味着您的 war
中可能有两个不同的 slf4j 库org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature
您可以使用该命令查找应用程序中注入的 slf4j 依赖项。
mvn dependency:tree -Dverbose -Dincludes=commons-collections
resolving conflicts using the dependency tree
并在 Maven 中排除依赖项:
<dependency>
[...]
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
<dependency>
您也可以解压缩 war 文件并在 WEB-INF/lib/ 中查找您拥有的不同版本的 slf4j。
问题已解决。我使用 mvn dependency:tree 查看依赖项:
ricardo@ricardo-SW6H:~/Documents/teste_rabbit/java-identity-provider/branches/3.1/idp-war$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Shibboleth IdP :: War
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] net.shibboleth.idp:idp-war:war:3.1.1
[INFO] +- org.slf4j:slf4j-api:jar:1.7.10:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.2:runtime
[INFO] | \- ch.qos.logback:logback-core:jar:1.1.2:runtime
[INFO] +- org.testng:testng:jar:6.8.8:compile
[INFO] | \- com.beust:jcommander:jar:1.47:compile (version managed from 1.27)
[INFO] +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.10:compile
[INFO] +- org.slf4j:jul-to-slf4j:jar:1.7.10:compile
[INFO] +- xmlunit:xmlunit:jar:1.5:compile
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.7.10:compile
[INFO] +- edu.vt.middleware:idp-memcached-storage:jar:1.0-SNAPSHOT:compile
[INFO] | +- net.spy:spymemcached:jar:2.11.4:compile
[INFO] | \- org.cryptacular:cryptacular:jar:1.0:compile
[INFO] +- net.shibboleth.idp:idp-attribute-api:jar:3.1.1:compile
[INFO] | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- net.shibboleth.idp:idp-attribute-filter-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-attribute-filter-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-attribute-filter-spring:jar:3.1.1:compile
[INFO] | +- org.springframework:spring-beans:jar:4.1.5.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:4.1.5.RELEASE:compile
[INFO] | \- org.springframework:spring-context:jar:4.1.5.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.1.5.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | \- org.springframework:spring-expression:jar:4.1.5.RELEASE:compile (version managed from 4.0.6.RELEASE)
[INFO] +- net.shibboleth.idp:idp-attribute-resolver-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-attribute-resolver-impl:jar:3.1.1:compile
[INFO] | +- org.apache.velocity:velocity:jar:1.7:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | \- commons-lang:commons-lang:jar:2.4:compile
[INFO] | +- joda-time:joda-time:jar:2.7:compile
[INFO] | +- org.ldaptive:ldaptive:jar:1.0.6:compile
[INFO] | \- javax.json:javax.json-api:jar:1.0:compile
[INFO] +- net.shibboleth.idp:idp-attribute-resolver-spring:jar:3.1.1:compile
[INFO] | \- com.mchange:c3p0:jar:0.9.2.1:compile
[INFO] | \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
[INFO] +- net.shibboleth.idp:idp-authn-api:jar:3.1.1:compile
[INFO] | \- org.glassfish:javax.json:jar:1.0.4:runtime
[INFO] +- net.shibboleth.idp:idp-authn-impl:jar:3.1.1:compile
[INFO] | \- org.springframework.webflow:spring-webflow:jar:2.4.1.RELEASE:compile
[INFO] | +- opensymphony:ognl:jar:2.6.11:compile
[INFO] | +- org.springframework.webflow:spring-binding:jar:2.4.1.RELEASE:compile
[INFO] | +- org.springframework.webflow:spring-js:jar:2.4.1.RELEASE:compile
[INFO] | | \- org.springframework.webflow:spring-js-resources:jar:2.4.1.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.1.5.RELEASE:compile
[INFO] +- net.shibboleth.idp:idp-consent:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-cas-api:jar:3.1.1:compile
[INFO] | \- org.springframework:spring-web:jar:4.1.5.RELEASE:compile
[INFO] +- net.shibboleth.idp:idp-cas-impl:jar:3.1.1:compile
[INFO] | \- org.apache.httpcomponents:httpclient:jar:4.3.6:compile
[INFO] | \- org.apache.httpcomponents:httpcore:jar:4.3.3:compile
[INFO] +- net.shibboleth.idp:idp-core:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-profile-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-profile-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-profile-spring:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-saml-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-saml-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-schema:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-session-api:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-session-impl:jar:3.1.1:compile
[INFO] +- net.shibboleth.idp:idp-ui:jar:3.1.1:compile
[INFO] +- net.shibboleth.ext:spring-extensions:jar:5.1.1:compile
[INFO] | \- org.apache.httpcomponents:httpclient-cache:jar:4.3.6:compile
[INFO] +- org.opensaml:opensaml-core:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-messaging-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-messaging-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-profile-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-profile-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-saml-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-saml-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-security-api:jar:3.1.1:compile
[INFO] | +- org.apache.santuario:xmlsec:jar:2.0.3:compile
[INFO] | | \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
[INFO] | | +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] | | \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] | \- org.bouncycastle:bcprov-jdk15on:jar:1.51:compile
[INFO] +- org.opensaml:opensaml-security-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-soap-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-soap-impl:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-storage-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-storage-impl:jar:3.1.1:compile
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:4.3.5.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] | | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | | +- org.hibernate:hibernate-core:jar:4.3.5.Final:compile
[INFO] | | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | | \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile
[INFO] | | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] | | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | \- org.springframework:spring-orm:jar:4.1.5.RELEASE:compile
[INFO] | +- org.springframework:spring-jdbc:jar:4.1.5.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:4.1.5.RELEASE:compile
[INFO] +- org.opensaml:opensaml-xmlsec-api:jar:3.1.1:compile
[INFO] +- org.opensaml:opensaml-xmlsec-impl:jar:3.1.1:compile
[INFO] +- com.google.code.findbugs:jsr305:jar:3.0.0:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- org.codehaus.janino:janino:jar:2.7.8:compile
[INFO] | \- org.codehaus.janino:commons-compiler:jar:2.7.8:compile
[INFO] +- net.shibboleth.utilities:java-support:jar:7.1.1:compile
[INFO] +- javax.mail:mail:jar:1.4.7:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.5.RELEASE:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:provided
[INFO] +- org.springframework:spring-test:jar:4.1.5.RELEASE:test
[INFO] \- net.shibboleth.utilities:java-support:test-jar:tests:7.1.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Sun Jul 05 21:56:37 CEST 2015
[INFO] Final Memory: 39M/345M
[INFO] ------------------------------------------------------------------------
使用这个结果,我将这个依赖项放在 pom.xml 中:
<!-- language:lang-xml -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.10</version>
</dependency>
现在问题解决了。非常感谢您的帮助。
这个问题可能是因为servlet容器中有jar(Ex Tomcat)。
例如:
- 有人在 tomcat 的库中保留了一些库(在本例中为 slf4j)。
- 您向 tomcat 部署了一个新项目。
- 在你的新项目中,你的一些依赖项依赖于那个库。
- 然后在你的新项目Tomcat和WAR中复制了同一个jar
然后你得到这样的错误信息。
解决这个问题的办法就是用"scope"说是提供了
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
<scope>provided</scope>
</dependency>
通过这样做,WAR 文件将不包含该依赖项。
如果您使用的是spring-boot-starter-web-1.5.1.RELEASE.jar,那么您需要排除jul -to-slf4j-1.7.22.jar,jcl-over-slf4j-1.7.22.jar.这两个jar有冲突slf4j-api.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>
WEB-INF/lib/jcl-over-slf4j-1.7.22.jar,WEB-INF/lib/jul-to-slf4j-1.7.22.jar
</packagingExcludes>
</configuration>
</plugin>