今天启动项目的时候出现jar包依赖冲突的问题,spring-boot项目默认使用logback日志库,然而又引入了log4j2导致出现下面的错误
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/86186/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/86186/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.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.apache.logging.slf4j.Log4jLoggerFactory] Exception in thread "main" java.lang.StackOverflowError at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:112) at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:125) at org.apache.logging.log4j.util.StackLocatorUtil.getCallerClass(StackLocatorUtil.java:55) at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:42) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
我使用的是gradle构建
所以在build.gradle里的dependencies里 将
implementation 'org.springframework.boot:spring-boot-starter-web'
改为
implementation('org.springframework.boot:spring-boot-starter-web'){
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
}
排除掉spring-boot-starter-web里的spring-boot-starter-logging的依赖即可解决


![使用IDEA解决包依赖冲突的问题 Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] 使用IDEA解决包依赖冲突的问题 Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]](http://www.mshxw.com/aiimages/31/851584.png)
