[英]"No SLF4J providers were found" after adding slf4j-api-2.0.0-alpha1.jar to the project structure and the slf4j dependency to the pom.xml
[英]Why would a "No SLF4J" provider found error occur when SLF4J is in Maven pom.xml file?
我目前在嘗試運行 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.
這是 pom.xml 文件中具有 SLF4J 和 Log4J 依賴項的部分。 同樣的部分在以前的項目中起作用。
<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>
我沒有任何針對 slf4j-api 版本 1..x 或更早版本的組件。 這個錯誤消息似乎都在說我沒有 SLF4J 並且我的版本有誤。
如果對如何解決此問題有任何想法,我將不勝感激。 謝謝!
我曾嘗試在 pom.xml 文件中使用不同的依賴項,但最終這些在之前的程序中都起作用了。 我還嘗試查看可能也使用 SLF4J 的依賴項並從中排除 SLF4J,但我仍然收到錯誤消息。 我已經嘗試過其他類似問題的解決方案,但一直出現相同的錯誤。
基於此文檔:
由於 SLF4J 綁定的兼容性中斷,從 2.19.0 版開始,提供了兩個 SLF4J 到 Log4j 適配器。
log4j-slf4j-impl
應該與 SLF4J 1.7.x 版本或更早版本一起使用。log4j-slf4j2-impl
應該與 SLF4J 2.0.x 版本或更新版本一起使用。利用 Java 模塊系統的應用程序應該使用 SLF4J 2.0.x 和 log4j-slf4j2-impl。
因此,最簡單的方法(如果您需要 SLF4J 2)是使用<artifactId>log4j-slf4j2-impl</artifactId>
。 您可以做的另一件事是恢復到slf4j-api
1.7.x。
其他注意事項:
SLF4J 日志顯示logback-classic
也存在於依賴樹中。 您需要 select logback-classic
或 log4j 綁定。 在您的項目上運行mvn dependency:tree
以查找添加logback-classic
的位置。
如果你想保留logback-classic
,那么和上面提到的一樣,你需要使用兼容 SLF4J 2 的logback-classic
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.