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

妖狐艹你老母 2021-09-02 05:20 1107阅读 0赞

【表现】线上打包后,tomcat下的项目无法启动,状态一直处在“暂停”。

【异常信息】

Caused by: 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:(项目路径此处省略)/WEB-INF/lib/slf4j-log4j12-1.7.28.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

翻译:java.lang.IllegalArgumentException:LoggerFactory不是Logback LoggerContext,但Logback在类路径上。 删除Logback或竞争的实现(从文件以下加载的org.slf4j.impl.Log4jLoggerFactory类:(项目路径此处省略)/WEB-INF/lib/slf4j-log4j12-1.7.28 。罐)。 如果使用的是WebLogic,则需要在WEB-INF / weblogic.xml中的“首选应用程序包”中添加“ org.slf4j”:org.slf4j.impl.Log4jLoggerFactory

【原因】两个日志jar包冲突,slf4j和Logback

【解决方法】

在pom.xml文件中

  1. 添加
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>ch.qos.logback</groupId>
  8. <artifactId>logback-classic</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>
  12. 或者添加
  13. <dependency>
  14. <groupId>org.apache.logging.log4j</groupId>
  15. <artifactId>log4j-slf4j-impl</artifactId>
  16. </dependency>

发表评论

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

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

相关阅读