简体   繁体   English

SLF4J:没有活页夹,然后是多个绑定,试图绑定到Log4J

[英]SLF4J: No Binder, and then Multiple Bindings, trying to Bind to Log4J

I have a strange double error with SLF4J. 我在SLF4J上遇到一个奇怪的双重错误。

I'm trying to get SLF4J to bind to Log4J. 我正在尝试让SLF4J绑定到Log4J。

In Eclipse, when I run a Maven Clean and then a Maven Install, I get this in the Maven Install output: 在Eclipse中,当我先运行Maven Clean然后进行Maven安装时,会在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.

Later on, when running the jUnit tests for the project, one of the tests calls a method that logs a message (I haven't cleaned it up to not log yet). 稍后,在为项目运行jUnit测试时,其中一个测试调用一种记录消息的方法(我还没有清除它以便不记录日志)。
But instead of logging, I get this message: 但是我没有记录,而是得到以下消息:

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.

So it seems that SLF4J first can't load a Binder, and then it finds multiple Bindings! 因此,似乎SLF4J首先无法加载活页夹,然后它找到多个绑定!

In my pom.xml, I have only one relevant dependency: 在我的pom.xml中,我只有一个相关的依赖项:

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

To resolve the issue, I tried deleting the first binding from my repository, namely this one: 为了解决此问题,我尝试从存储库中删除第一个绑定,即以下一个:

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

I ran another Maven Clean, Maven Install and got a strange error when it tried to run the tests: 我运行了另一个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

I then ran Maven Clean, Maven Install again, and got the original "Multiple Bindings" error again, and found that the directory I had deleted was there again as if I hadn't deleted it. 然后,我再次运行Maven Clean,再次运行Maven Install,并再次出现原始的“多重绑定”错误,发现我删除的目录又在那里,就好像我没有删除它一样。

I don't know what else I can do to get rid of the "Multiple Bindings" error. 我不知道我还能做些什么来摆脱“多重绑定”错误。

Note: I found a similar question , but I don't have the same cause that could be effecting this error. 注意:我发现了一个类似的问题 ,但原因不相同,可能会导致此错误。

Also, the "No Binder Found" error at the top might be because of this , though I'm not sure. 另外,虽然我不确定,但顶部的“找不到活页夹”错误可能是由于原因。

It turns out that another dependency (We'll call it Dependency A ) in my project has, among its own dependencies, a dependency on ch.qos.logback:logback-classic. 事实证明,我项目中的另一个依赖项(我们将其称为Dependency A )在其自身的依赖项中具有对ch.qos.logback:logback-classic.的依赖ch.qos.logback:logback-classic. Adding exclusions for this dependency to Dependency A resulted in errors, so I decided to ditch trying to bind to log4j and just let it bind to logback-classic . 将此依赖项的排除项添加到Dependency A会导致错误,因此我决定放弃尝试绑定到log4j而仅使其绑定到logback-classic

I removed the dependency: 我删除了依赖项:

slf4j-log4j13

I then replaced it with: 然后,我将其替换为:

slf4j-api

This removed the multiple-bindings error. 这消除了多重绑定错误。

I'm assuming the top error message of no bindings is due to the fact that it is given before the dependencies of dependencies are downloaded. 我假设没有绑定的最大错误消息是由于在下载依赖项的依赖项之前给出的。 So I'm going to ignore it as my code works just fine. 所以我将忽略它,因为我的代码可以正常工作。

It seems to me that you have multiple bindings in your test dependencies (either explicit, or implicit as dependencies of dependencies). 在我看来,您在测试依赖项中有多个绑定(显式或隐式作为依赖项的依赖项)。

Your "normal" (non-test) dependencies do not have the same issue - the don't in fact include a single SFL4j binding. 您的“正常”(非测试)依赖项没有相同的问题-实际上不包含单个SFL4j绑定。

Note that, not being a user of either Maven or Eclipse, I have no idea how to solve the problem. 请注意,由于既不是Maven也不是Eclipse的用户,所以我不知道如何解决该问题。 I'm just pointing out what looks like the root of the issue, hoping that a) I'm right and b) that'll be enough for you to work the rest out. 我只是指出看起来像是问题的根源,希望a)我是对的,b)足以让您进行其余工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM