Deployment on Tomcat: Constraint violation when resolving method “org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;”

前端 未结 4 1427
醉梦人生
醉梦人生 2021-02-10 10:46

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.listenerS         


        
相关标签:
4条回答
  • 2021-02-10 11:11

    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>      
    
    0 讨论(0)
  • 2021-02-10 11:16

    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.

    0 讨论(0)
  • 2021-02-10 11:18

    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.

    0 讨论(0)
  • 2021-02-10 11:24

    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.

    0 讨论(0)
提交回复
热议问题