我是spring boot的新手,当我尝试启动我的服务器时,我得到了以下异常。我知道这与依赖冲突有关,但仍然无法解决它。我正在使用maven来管理我的dependencies.Please帮助
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>发布于 2014-12-19 20:42:10
从spring-boot-starter-web和spring-boot-starter-actuator中排除logback-classic对我很管用
compile("org.springframework.boot:spring-boot-starter-web:1.1.10.RELEASE") {
exclude module: "spring-boot-starter-tomcat"
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile("org.springframework.boot:spring-boot-starter-actuator:1.1.10.RELEASE") {
exclude module: "logback-classic"
}发布于 2016-06-13 14:32:57
将此代码添加到您的build.gradle
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'org.springframework.boot', module: 'logback-classic'
}发布于 2017-02-08 08:20:41
在我的项目中,它使用
第一个Introduction to the Dependency Mechanism
依赖项中介-当遇到多个版本的工件时,它确定将使用哪个版本的依赖项。目前,Maven2.0只支持使用“最近的定义”,这意味着它将使用依赖关系树中与您的项目最接近的依赖关系的版本。您总是可以通过在项目的POM中显式声明它来保证版本。请注意,如果两个依赖项版本在依赖关系树中的深度相同,则直到Maven 2.0.8之前都没有定义哪一个会胜出,但从Maven 2.0.9开始,重要的是声明中的顺序:第一个声明获胜。“最近的定义”意味着使用的版本将是依赖树中最接近您的项目的版本,例如。如果A、B和C的依赖项定义为A -> B -> C -> D 2.0和A -> E -> D 1.0,则在构建A时将使用D 1.0,因为通过E从A到D的路径较短。您可以显式地向A中的D2.0添加依赖项,以强制使用D2.0
因此,maven将在我的项目中使用logback 1.1.7。我不确定是我的模块A与1.1.7不兼容,还是logback 1.1.7与slf4j 1.7.21不兼容,在我的情况下。我在我的pom中添加了dependencyManagement。告诉maven只使用lockback 1.1.2。问题解决了。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
</dependencyManagement>https://stackoverflow.com/questions/26061860
复制相似问题