相关异常信息如下:

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:~/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.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
    at org.springframework.util.Assert.instanceCheckFailed(Assert.java:696)
    at org.springframework.util.Assert.isInstanceOf(Assert.java:596)

关键信息

 

 

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation……

 

此时,可用过查看maven依赖来排查问题,在项目跟目录执行如下命令:

mvn dependency:tree

显示如下

[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.3.3.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot:jar:1.3.3.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.3.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE:compile [INFO] | | +- ch.qos.logback:logback-classic:jar:1.1.5:compile [INFO] | | | \- ch.qos.logback:logback-core:jar:1.1.5:compile [INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile [INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.5:compile [INFO] | | \- org.slf4j:log4j-over-slf4j:jar:1.7.5:compile [INFO] | +- org.springframework:spring-core:jar:4.2.5.RELEASE:compile [INFO] | \- org.yaml:snakeyaml:jar:1.16:compile ... [INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile [INFO] | \- org.slf4j:slf4j-api:jar:1.7.5:compile

排除冲突

<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>

 

解决

 

 

程序员成长之路     http://jzi5.cn/kYxu5z

 

 

 

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐