解決spring-boot-starter-logging與log4j沖突


 

 

由於公司在super-bom里配置了檢查規則,build項目時遇到錯誤:

[ERROR] [XXX Enforcer Rules] find DuplicateClasses

Found in:
org.apache.logging.log4j:log4j-slf4j-impl:jar:2.6.2:compile
ch.qos.logback:logback-classic:jar:1.1.7:compile
Duplicate classes:
org/slf4j/impl/StaticMDCBinder.class
org/slf4j/impl/StaticMarkerBinder.class
org/slf4j/impl/StaticLoggerBinder.class

我在pom里並沒有直接引用logback-classic,看到這個錯誤就懵了,我在pom里沒有引用這個啊。

解決過程:

可以通過IntelliJ Idea的包依賴查看找出是哪個包依賴了logback-classic。操作:View->Tool Window->Maven Projects,這個按鈕:

可以看到package依賴圖,可能會比較復雜、雜亂,Ctrl+F后可以搜索到:

這篇博客有提到如何處理這個問題:http://blog.csdn.net/xudan1010/article/details/52890102,即使用excusions來排除spring-boot-starter對spring-boot-starter-logging的依賴,然后引入log4j-slf4j-impl

復制代碼
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
復制代碼

 另可以使用命令來看依賴:mvn dependency:tree | grep log


 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM