【问题标题】:SLF4J: Class path contains multiple SLF4J bindings warningSLF4J:类路径包含多个 SLF4J 绑定警告
【发布时间】:2021-05-19 08:36:57
【问题描述】:

我在其他问题中看到,通常解决此警告的方法是将 slf4j 从导致此冲突的依赖项中排除,但我无法在我的项目中发现问题。

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Applications/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/Applications/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]

我运行mvn dependency:tree 命令,这是输出:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ subscriptionsmanager ---
[INFO] it.pietro:subscriptionsmanager:jar:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.13.1:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.mockito:mockito-core:jar:3.5.13:test
[INFO] |  +- net.bytebuddy:byte-buddy:jar:1.10.15:test
[INFO] |  +- net.bytebuddy:byte-buddy-agent:jar:1.10.15:test
[INFO] |  \- org.objenesis:objenesis:jar:3.1:test
[INFO] +- org.mongodb:mongo-java-driver:jar:3.12.7:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- de.bwaldvogel:mongo-java-server:jar:1.11.1:compile
[INFO] |  +- de.bwaldvogel:mongo-java-server-core:jar:1.11.1:compile
[INFO] |  |  +- io.netty:netty-transport:jar:4.1.31.Final:compile
[INFO] |  |  |  +- io.netty:netty-buffer:jar:4.1.31.Final:compile
[INFO] |  |  |  |  \- io.netty:netty-common:jar:4.1.31.Final:compile
[INFO] |  |  |  \- io.netty:netty-resolver:jar:4.1.31.Final:compile
[INFO] |  |  \- io.netty:netty-codec:jar:4.1.31.Final:compile
[INFO] |  \- de.bwaldvogel:mongo-java-server-memory-backend:jar:1.11.1:compile
[INFO] +- org.assertj:assertj-core:jar:3.15.0:test
[INFO] +- org.testcontainers:mongodb:jar:1.15.1:compile
[INFO] |  \- org.testcontainers:testcontainers:jar:1.15.1:compile
[INFO] |     +- org.apache.commons:commons-compress:jar:1.20:compile
[INFO] |     +- org.rnorth.duct-tape:duct-tape:jar:1.0.8:compile
[INFO] |     +- org.rnorth.visible-assertions:visible-assertions:jar:2.1.2:compile
[INFO] |     |  \- net.java.dev.jna:jna:jar:5.2.0:compile
[INFO] |     +- com.github.docker-java:docker-java-api:jar:3.2.7:compile
[INFO] |     |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.3:compile
[INFO] |     \- com.github.docker-java:docker-java-transport-zerodep:jar:3.2.7:compile
[INFO] |        \- com.github.docker-java:docker-java-transport:jar:3.2.7:compile
[INFO] +- org.assertj:assertj-swing-junit:jar:3.17.1:test
[INFO] |  +- org.assertj:assertj-swing:jar:3.17.1:test
[INFO] |  |  \- org.easytesting:fest-util:jar:1.2.5:test
[INFO] |  \- org.easytesting:fest-reflect:jar:1.4.1:test
[INFO] \- info.picocli:picocli:jar:4.5.2:compile

【问题讨论】:

  • 是的,但我不明白是什么依赖导致了冲突。
  • 鉴于提到的路径之一来自 Eclipse,我猜问题是 Eclipse 在路径上添加了一些额外的东西。
  • @MarkRotteveel 你能举个例子吗?
  • 更改pom.xml后,是否右键单击项目并Maven>更新项目...?请显示 Eclipse 执行的命令行(在运行配置中有一个 Show Command Line 按钮)。

标签: java eclipse maven pom.xml slf4j


【解决方案1】:

SLF4J 绑定警告来自 Eclipse IDE 本身,并且与您在 Eclipse IDE 中编写的应用程序无关。所以这只是可以忽略的噪音(参见例如herehere)。

我猜你有 Eclipse IDE for Enterprise Java Developers 可能安装了一些额外的插件。那是 900 多个 JAR。 SLF4J 被用于 Eclipse 的 Maven 支持(在 SLF4J 绑定警告中为 m2e)以及至少一个其他插件以不兼容的方式导致此警告。 Eclipse 基于 OSGi,其中没有平面类路径,并且可以在运行时安装、启动、停止和卸载插件/捆绑包。 SLF4J 似乎在构建时并未考虑到 OSGi,因此会出现误导性警告 Class path contains multiple SLF4J bindings,尽管 OSGi 中没有使用自己的类加载器的类路径。

【讨论】:

    【解决方案2】:

    您可以通过在导致冲突的依赖项(pom.xml)中添加以下排除项来解决此问题。

     <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
     </exclusions> 
    

    【讨论】:

    • 但是我不明白是哪个依赖导致了冲突。
    • 这里不起作用,因为它是由Eclipse引起的。
    猜你喜欢
    • 2012-12-11
    • 2016-03-12
    • 2014-05-18
    • 2020-07-07
    • 2018-12-12
    • 2013-01-28
    • 2012-09-11
    • 2018-07-29
    相关资源
    最近更新 更多