springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式

 

springboot 项目启动server子模块时,报了

"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/it00013196/.m2/repository/org/slf4j/slf4j-log4j12/1.7.26/slf4j-log4j12-1.7.26.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" 的错误。

根据提示是要移除logback或slf4j-log4j12其中一个,但是pom中并没有引入这两个包的语句。

移除logback

本文先从移除logback入手。

(1)找到引入logback的包

在idea, view -> Tools Windows -> maven

springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式_第1张图片

在maven窗口中,选中server子模块,点击maven窗口上方的show dependencies

springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式_第2张图片

按 command + f ,找到logback-core,单击

springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式_第3张图片

显示依赖图,在依赖图中找到引用logback的是mybatis(不一定都是mybatis,也可能是其他依赖引用的,在依赖图找到它)

springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式_第4张图片

打开pom.xml,在引入mybatis的部分加入排除logback的语句,再启动,问题解决。

springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式_第5张图片

 

移除slf4j-log4j12

方式与移除logback一样,到依赖图中找引入slf4j-log4j12的点,然后将slf4j-log4j12移除掉,我是zkclient这一依赖中引入了slf4j-log4j12。

springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式_第6张图片

你可能感兴趣的:(springboot)