【问题标题】:SLF4J: No Binder, and then Multiple Bindings, trying to Bind to Log4JSLF4J:没有Binder,然后是多个绑定,试图绑定到Log4J
【发布时间】:2013-09-18 16:29:30
【问题描述】:

我对 SLF4J 有一个奇怪的双重错误。

我正在尝试让 SLF4J 绑定到 Log4J。

在 Eclipse 中,当我运行 Maven Clean 和 Maven Install 时,我会在 Maven Install 输出中看到:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

稍后,在为项目运行 jUnit 测试时,其中一个测试调用了一个记录消息的方法(我还没有清理它以不记录)。
但我没有记录,而是收到以下消息:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/JDunn/.m2/repository/ch/qos/logback/logback-classic/0.9.30/logback-classic-0.9.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/JDunn/.m2/repository/org/slf4j/slf4j-log4j13/1.0.1/slf4j-log4j13-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

所以看来SLF4J先是加载不了一个Binder,然后才找到多个Bindings!

在我的 pom.xml 中,我只有一个相关的依赖项:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j13</artifactId>
    <version>1.0.1</version>
</dependency>

为了解决这个问题,我尝试从我的存储库中删除第一个绑定,即这个:

C:/Users/JDunn/.m2/repository/ch/qos/logback/logback-classic/0.9.30/logback-classic-0.9.30.jar

我运行了另一个 Maven Clean、Maven Install 并在尝试运行测试时遇到了一个奇怪的错误:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test (default-test) on project sonar-score-plugin: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test failed: There was an error in the forked process

然后我又运行了Maven Clean,Maven Install,又出现了原来的“Multiple Bindings”错误,发现我删除的目录又出现了,就好像我没有删除一样。

我不知道我还能做些什么来摆脱“多重绑定”错误。

注意:我找到了 similar question,但我没有可能导致此错误的相同原因。

另外,顶部的“No Binder Found”错误可能是因为this,虽然我不确定。

【问题讨论】:

  • 您是否使用 Eclipse 作为 IDE。如果是,您使用的是什么版本的 m2e。?

标签: java maven slf4j


【解决方案1】:

事实证明,我的项目中的另一个依赖项(我们将其称为 Dependency A)在它自己的依赖项中,有一个对 ch.qos.logback:logback-classic. 的依赖项,将此依赖项的排除项添加到 依赖项 A 导致错误,所以我决定放弃尝试绑定到 log4j 并让它绑定到 logback-classic

我删除了依赖:

slf4j-log4j13

然后我将其替换为:

slf4j-api

这消除了多重绑定错误。

我假设没有绑定的顶部错误消息是由于它是在下载 依赖项的依赖项 之前给出的。所以我会忽略它,因为我的代码工作得很好。

【讨论】:

    【解决方案2】:

    在我看来,您的测试依赖项中有多个绑定(显式或隐式作为依赖项的依赖项)。

    您的“正常”(非测试)依赖项没有相同的问题 - 实际上不包含单个 SFL4j 绑定。

    请注意,我不是 Maven 或 Eclipse 的用户,我不知道如何解决这个问题。我只是指出问题的根源,希望 a) 我是对的 b) 这足以让你解决剩下的问题。

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 2018-07-10
      • 2014-10-31
      • 2012-09-28
      • 2013-10-01
      • 2016-01-09
      • 2015-04-24
      • 1970-01-01
      相关资源
      最近更新 更多