7

I'm deploying Shibboleth IdP 3.1.1 on Tomcat 8.0.22, but I receive this error:

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

Information about the java version:

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)

I put in $CATALINA_HOME/lib the jars: slf4j-api-1.7.12.jar, slf4j-log4j12-1.7.12.jar and nlog4j-1.2.14.jar

But that does not solve the problem. I tried put org.slf4j as a dependency in maven, but don't work too.

Is there a way to resolve this exception? Thanks for any suggestion.

Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100

4 Answers4

16

This mean you probably have two different librairies of slf4j in your war

org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature

You can use that command to find slf4j dependencies injected in your application.

mvn dependency:tree -Dverbose -Dincludes=commons-collections

resolving conflicts using the dependency tree

And Exclude dependancies in Maven:

<dependency>    
    [...]
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
    </exclusions>
<dependency>

You can also unzip your war file and look in WEB-INF/lib/ to find the different versions of slf4j that you have.

bodyjares
  • 440
  • 1
  • 4
  • 16
3

This problem may be because there is a jar in the servlet container (Ex Tomcat).

For example:

  • someone had kept some lib (In this case slf4j) in a tomcat's lib.
  • you deployed a new project to that tomcat.
  • In your new project, some of your dependencies have dependencies to that lib.
  • Then there is duplicated of the same jar in Tomcat and WAR of your new project

Then you get such an error message.

The way to solve this is just use "scope" to say that it is provided.

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.6</version>
            <scope>provided</scope>
        </dependency>

By doing this, the WAR file will not include that dependency.

Surasin Tancharoen
  • 5,520
  • 4
  • 32
  • 40
0

Problem solved. I used mvn dependency:tree to see the dependencies:

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] ------------------------------------------------------------------------

Using this result I put this dependencies in the 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>

Now the problem is solved. Thank you very much for the help.

Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100
0

If you are using spring-boot-starter-web-1.5.1.RELEASE.jar,then you need to exclude jul-to-slf4j-1.7.22.jar,jcl-over-slf4j-1.7.22.jar.These two jar have conflict 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>      
Cà phê đen
  • 1,883
  • 2
  • 21
  • 20
navin shah
  • 51
  • 3