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

解決:Failed to load class "org.slf4j.impl.StaticLoggerBinder".

控制檯輸出

這裡寫圖片描述

版本

<!-- slf4j -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
   <version>1.7.21</version>
 </dependency>

 <!-- log4j -->
 <dependency>
   <groupId>log4j</groupId>
   <artifactId
>
log4j</artifactId> <version>1.2.17</version> </dependency>

原因

sl4j和log4j的不相容。需要在兩者之間新增jar包

解決

  1. 使用slf4j-log4j12 ,版本與 slf4j 一致,去掉 test scope。
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version
>
1.7.21</version> </dependency>

maven依賴檢視,是正確的
這裡寫圖片描述
2. 使用 log4j-slf4j-impl
在maven中央倉庫中去查詢依賴的 jar 包,新增上去就可以了,但具體沒實踐過

注意:
slf4j-log4j12 log4j-slf4j-impl 不能同時用