SpringBoot LoggerFactory is not a Logback LoggerContext but Logback is on the classpath。。。

水深无声 2022-05-11 08:16 241阅读 0赞

SpringBoot 在启动项目的时候一起错误:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/tongqinyuan/.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:/Users/tongqinyuan/.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.slf4j.impl.Log4jLoggerFactory]
Exception in thread “main” java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/Users/tongqinyuan/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar). If you are using WebLogic you will need to add ‘org.slf4j’ to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory

其实这是slf4j 日志包冲出导致 ,怎么查看包冲突呢?

zookeeper包和junit包中都引入了日志包:

  1. <dependency>
  2. <groupId>org.apache.zookeeper</groupId>
  3. <artifactId>zookeeper</artifactId>
  4. <exclusions>
  5. <exclusion>
  6. <artifactId>slf4j-log4j12</artifactId>
  7. <groupId>org.slf4j</groupId>
  8. </exclusion>
  9. </exclusions>
  10. </dependency>

安装maven help 插件,在pom.xml文件下点击dependency Analyzer分析查看冲突的包

70

70 1

找到冲突后通过exclude排除掉就好了;

发表评论

表情:
评论列表 (有 0 条评论,241人围观)

还没有评论,来说两句吧...

相关阅读