【发布时间】:2014-09-26 14:23:00
【问题描述】:
我是 Spring Boot 新手,当我尝试启动我的服务器时,我得到以下异常。我知道这与依赖冲突有关,但仍然无法弄清楚。我正在使用 maven 来管理我的依赖关系。请帮助
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) Object of class
[org.slf4j.impl.Log4jLoggerFactory] must be an instance of class
ch.qos.logback.classic.LoggerContext at
org.springframework.util.Assert.isInstanceOf(Assert.java:339) at
org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:93)
at
org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSensibleDefaults(AbstractLoggingSystem.java:62)
at
org.springframework.boot.logging.AbstractLoggingSystem.beforeInitialize(AbstractLoggingSystem.java:45)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:69)
at
org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:135)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
at
org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100)
at
org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:54)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:276)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at org.magnum.mobilecloud.video.Application.main(Application.java:30)
已解决:在 POM.xml 中添加以下内容
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
【问题讨论】:
-
你能提供你的
pom.xml吗? -
您好,终于通过排除Logback依赖并显式添加log4j依赖解决了这个问题。
-
很高兴听到你想通了。回答您自己的问题没有害处:您应该将您的解决方案作为答案发布并接受它。我对 Spring Boot 进行了改进,以便它能够识别竞争 LoggerFactory 实现的来源,并希望使问题更容易诊断:github.com/spring-projects/spring-boot/commit/…
-
安迪,gr8...谢谢你
-
我知道这是一个老问题,但为了未来的读者:记住“mvn dependency:tree”任务是你的朋友。它需要一些工作——例如,你必须认识到 org.slf4j:slf4j-simple 与 logback 冲突——但是当面临这个问题时(通常是因为传递依赖),以树形式查看依赖通常会让我走上通往解决方案。
标签: log4j spring-boot