1. 程式人生 > >SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

iat depend 路徑 pad 通過 order splay 之一 pre

最近在學習SpringBoot時,有的時候明明項目運行起來沒有問題,但是Console控制臺會報錯,比如說如下的問題異常提示:

技術分享

由此我們可以看出,報出錯誤的地方主要是slf4j的jar包,而故障碼中“Failed to load class ’org.slf4j.impl.StaticLoggerBinder‘”的意思則是“加載類文件org.slf4j.impl.StaticLoggerBinder時失敗”。

而官網上刊登的解決辦法是:

This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

翻譯過來如下所示:

這個錯誤是當org.slf4j.impl報道。StaticLoggerBinder類不能被加載到內存中。發生這種情況時,無法找到合適的SLF4J綁定類路徑。slf4j-nop.jar放置一個(且只有一個), slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar 或 logback-classic.jar 的類路徑應該解決這個問題。

所以說解決的辦法就是在Maven工程的pom文件中隨便加載一個上述的包文件之一的依賴就可以了(且只有一個),此時我加載的是“slf4j-nop-1.7.2.jar”包文件的依賴,然後整個項目就可以編譯無異常通過了。

  1 <dependency>
  2     <groupId>org.slf4j</groupId>
  3     <artifactId>slf4j-nop</artifactId>
  4     <version>1.7.2</version>
  5 </dependency>

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".