詳細錯誤信息如下:
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/eluzhu/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/eluzhu/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details. Exception in thread “main” java.lang.ExceptionInInitializerError at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:72) at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:45) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:149) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:390) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:340) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:361) at com.eluzhu.sass.Application.(Application.java:13) Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details. at org.slf4j.impl.Log4jLoggerFactory.(Log4jLoggerFactory.java:54) … 8 more
如圖所示:
關鍵錯誤信息:Class path contains multiple SLF4J bindings.
翻譯過來的意思是:類路徑包含多個SLF4J綁定。
分析原因:類路徑包含多個SLF4J綁定,也就是代表這有很多個SLF4J,這就表示重復了,在Maven中出現這種情況,會導致一個叫Maven沖突的玩意,主要體現jar方面的沖突。
解決辦法:
排除即可
<!-- 騰訊雲 --> <dependency> <groupId>com.qcloud</groupId> <artifactId>cos_api</artifactId> <version>5.2.4</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency>
使用exclusion就可以排除相關的依賴
那么為什么會出現這種情況呢?
是因為Maven一個重要特性,即依賴傳遞。依賴傳遞的表現是,一個maven依賴可能包含多個相關Jar,結合實際開發項目,為了實現某些特定的功能,我們需要引入特定的jar(當然了,也可以選擇自己動手寫一個,不過那樣的話,時間成本會比較高),特定的Jar對應特定的功能,通常一個Maven項目需要引入多個依賴(jar)。
如果你還是不太明白什么是依賴傳遞,如圖所示(我相信圖能夠生動形象的體現出來):