SLF4J加載類org.slf4j.impl.StaticLoggerBinder失敗

一、Console控制檯輸出異常,加載類 org.slf4j.impl.StaticLoggerBinder失敗

IDEA 運行時,Console控制檯輸出信息:

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.


SLF4J加載類org.slf4j.impl.StaticLoggerBinder失敗


上面的意思是:加載類文件org.slf4j.impl.StaticLoggerBinder時失敗。在缺少binding的情況下,默認加載NOP logger實現。


二、官網分析和說明

可以訪問上面提示的鏈接,查看官網提供的解決方案:

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.

SINCE 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.


中文說明:

無法加載類 org.slf4j.impl.StaticLoggerBinder

當無法將類org.slf4j.impl.StaticLoggerBinder加載到內存中時,會報告此警告消息 。如果在類路徑上找不到合適的SLF4J綁定,就會發生這種情況。在類路徑中放置slf4j-nop.jar、slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar或 logback-classic.jar中的一個(並且只有一個)應該可以解決問題。

自1.6.0起,SLF4J版本1.6 以來,在沒有綁定的情況下,SLF4J將默認為無操作(NOP)記錄器實現。


如果您負責打包應用程序並且不關心日誌記錄,那麼將slf4j-nop.jar放在應用程序的類路徑中將擺脫此警告消息。請注意,嵌入式組件(如庫或框架)不應聲明對任何SLF4J綁定的依賴關係,但僅依賴於slf4j-api。當庫聲明對SLF4J綁定的編譯時(compile-time)依賴性時,它會將該綁定強加給最終用戶,從而否定SLF4J的目的。


三、具體解決方案

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

<dependency>

<groupid>org.slf4j/<groupid>

<artifactid>slf4j-nop/<artifactid>

<version>1.7.25/<version>


或者添加slf4j-log4j12.jar包依賴:

<dependency>

<groupid>org.slf4j/<groupid>

<artifactid>slf4j-log4j12/<artifactid>

<version>1.7.25/<version>


添加好依賴包之後,再次編譯就沒有前面的警告信息了。

SLF4J加載類org.slf4j.impl.StaticLoggerBinder失敗


分享到:


相關文章: