[英]Why would a "No SLF4J" provider found error occur when SLF4J is in Maven pom.xml file?
I am currently getting the below errors when trying to run a Spring Java program.我目前在尝试运行 Spring Java 程序时遇到以下错误。
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J: Ignoring binding found at [jar:file:/C:/Users/user/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Ignoring binding found at [jar:file:/C:/Users/user/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.19.0/log4j-slf4j-impl-2.19.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.
Here is the section in the pom.xml file that has the SLF4J and Log4J dependencies.这是 pom.xml 文件中具有 SLF4J 和 Log4J 依赖项的部分。 This same section has worked in previous projects.同样的部分在以前的项目中起作用。
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
I don't have any components that are targeting indings for slf4j-api version 1..x or earlier.我没有任何针对 slf4j-api 版本 1..x 或更早版本的组件。 This error message seems to both say that I don't have SLF4J and that I have the wrong version.这个错误消息似乎都在说我没有 SLF4J 并且我的版本有误。
If there are any thoughts on how to resolve this, I would appreciate it.如果对如何解决此问题有任何想法,我将不胜感激。 Thank you!谢谢!
I have tried using different dependencies in the pom.xml file, but ultimately these have worked in a previous program.我曾尝试在 pom.xml 文件中使用不同的依赖项,但最终这些在之前的程序中都起作用了。 I have also tried looking at dependencies that might also use SLF4J and excluding SLF4J from them, but I am still getting an error message.我还尝试查看可能也使用 SLF4J 的依赖项并从中排除 SLF4J,但我仍然收到错误消息。 I have tried solutions from other similar questions asked but keep getting the same error.我已经尝试过其他类似问题的解决方案,但一直出现相同的错误。
Based on this documentation :基于此文档:
Due to a break in compatibility in the SLF4J binding, as of release 2.19.0 two SLF4J to Log4j Adapters are provided.由于 SLF4J 绑定的兼容性中断,从 2.19.0 版开始,提供了两个 SLF4J 到 Log4j 适配器。
log4j-slf4j-impl
should be used with SLF4J 1.7.x releases or older.log4j-slf4j-impl
应该与 SLF4J 1.7.x 版本或更早版本一起使用。log4j-slf4j2-impl
should be used with SLF4J 2.0.x releases or newer.log4j-slf4j2-impl
应该与 SLF4J 2.0.x 版本或更新版本一起使用。Applications that take advantage of the Java Module System should use SLF4J 2.0.x and log4j-slf4j2-impl.利用 Java 模块系统的应用程序应该使用 SLF4J 2.0.x 和 log4j-slf4j2-impl。
So the simplest way (if you need SLF4J 2) is to use <artifactId>log4j-slf4j2-impl</artifactId>
.因此,最简单的方法(如果您需要 SLF4J 2)是使用<artifactId>log4j-slf4j2-impl</artifactId>
。 The other thing you can do is to revert back to slf4j-api
1.7.x.您可以做的另一件事是恢复到slf4j-api
1.7.x。
Other notes:其他注意事项:
The SLF4J log shows that logback-classic
is also present in the dependency tree. SLF4J 日志显示logback-classic
也存在于依赖树中。 You need to select either logback-classic
or the log4j binding.您需要 select logback-classic
或 log4j 绑定。 Run mvn dependency:tree
on your project to find where logback-classic
is being added.在您的项目上运行mvn dependency:tree
以查找添加logback-classic
的位置。
If you want to keep logback-classic
, then same as mentioned above, you need to use the logback-classic
compatible with SLF4J 2.如果你想保留logback-classic
,那么和上面提到的一样,你需要使用兼容 SLF4J 2 的logback-classic
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.