SLF4J: Class path contains multiple SLF4J bindings(log4j與logback衝突了)
阿新 • • 發佈:2019-02-16
當你啟動service或者web專案的時候,出現瞭如下詳細地異常,那說明你配置的log4j與logback jar包發生了衝突:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/G:/m2/repository/org/slf4j/slf4j-log4j12/1.7.22/slf4j-log4j12-1.7.22.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/G:/m2/repository/ch/qos/logback/logback-classic/1.1.8/logback-classic-1.1.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
就比如,我的web專案用logback日誌,通過檢視jar包依賴列表,並沒有發現有log4j的蹤影。但是,一定要注意,專案依賴的任何jar,有可能你本身的專案沒引用,像我引用了公共的jar,說不定裡面就包含了log4j導致了衝突,我的就是這樣。
雙擊展開引用,問題的根源找到了。
我在jar包引用的地方,遮蔽log4j。
<exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions>