SLF4J错误:类路径包含多个SLF4J绑定



我已经在第三天出现了这个错误,我无法解决。有一些东西我无法理解,无论我怎么做,错误仍然存在。

我正在读一本叫做"詹金斯权威指南"的书(http://www.wakaleo.com/books/jenkins-the-definitive-guide),我被困在第二章了。基本上是一个例子,如何使用Jenkins与Javadoc, JUnit和Cobertura插件的Jenkins。一切工作,直到我得到Cobertura插件部分,在那里我得到下一个错误:

[ERROR] SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Windows/System32/config/systemprofile/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Windows/System32/config/systemprofile/.m2/repository/org/slf4j/slf4j-simple/1.6.1/slf4j-simple-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

我看到过像我这样的其他问题,我得到的结论是,我必须在我的pom.xml文件/s中包含或排除依赖项(这个例子在这个阶段只使用pom文件)。包含slf4j-simple的pom.xml文件如下所示:

<project>
......
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
    </dependencies>
</project>

和没有显式依赖于logback-classic,因此我不知道在哪个依赖被使用。我试图使用jenkins的依赖插件,我得到了这个结果:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ gameoflife-web ---
[INFO] com.wakaleo.gameoflife:gameoflife-web:war:1.0-SNAPSHOT
[INFO] +- com.wakaleo.gameoflife:gameoflife-core:jar:1.0-SNAPSHOT:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-asm:jar:3.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.0.2.RELEASE:compile
[INFO] |  |  - org.springframework:spring-aop:jar:3.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:3.0.2.RELEASE:compile
[INFO] |  - org.springframework:spring-expression:jar:3.0.2.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:3.0.2.RELEASE:compile
[INFO] |  - commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-web:jar:3.0.2.RELEASE:compile
[INFO] |  - aopalliance:aopalliance:jar:1.0:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test
[INFO] +- org.easytesting:fest-assert:jar:1.4:compile
[INFO] |  - org.easytesting:fest-util:jar:1.1.6:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.6.1:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  - org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] - org.hamcrest:hamcrest-all:jar:1.1:test

也许我是盲人,但我仍然看不到谁使用logback-classic(顺便说一下,我不确定logback-classic值是正确的)。我试图删除slf4j依赖项,我的错误消失了,但我没有得到任何cobertura报告。我尝试用

排除logback-classic
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
        <exclusions>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
        <exclusions>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

,错误仍然存在。我不知道该怎么办了,请帮帮我吧!

好消息是,即使SLF4J报告错误,它实际上警告您SLF4J将绑定到ch.qos.logback.classic.util.ContextSelectorStaticBinder,因为在类路径上有两个可用的绑定。SLF4J将选择类路径上可用的第一个。您的应用程序应该继续正常工作,尽管使用logback进行日志记录。

我不能告诉你为什么logback-classic.jar在类路径上,但是我建议你调查一下类路径中提到的"System profile"

您试图从self依赖项本身中排除logback-classic。问题是,正如这里提到的,您在类路径中使用了多个绑定。实际的方法是将logback-classic排除在使用它的依赖项中,而不是在slf4j依赖项中。不幸的是,我不确定您的哪些jar,正在引用导致问题的slf4j。一种解决方法是,使用Ctrl+Sft+T查看在不同的jar中是否存在StaticLoggerBinder类,并将logback-classic排除在其中。另一种解决方法是,你可以试着保持排除,试错。这些只是变通,但概念是一样的。我们需要在类路径

中找到其他引用logback-classic的依赖项。

请遵循以下规则步骤

步骤1:使用mvn依赖项:tree

确定经典的登录返回

步骤2:在pom.xml

中添加以下排除
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-to-slf4j</artifactId>
                </exclusion>
            </exclusions>
Step3:测试应用程序

积分归https://java2blog.com/fixed-slf4j-warning-class-path-contains-multiple-slf4j-bindings/

最新更新