首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法启动spring boot服务器

无法启动spring boot服务器
EN

Stack Overflow用户
提问于 2014-09-26 22:23:00
回答 10查看 37K关注 0票数 28

我是spring boot的新手,当我尝试启动我的服务器时,我得到了以下异常。我知道这与依赖冲突有关,但仍然无法解决它。我正在使用maven来管理我的dependencies.Please帮助

代码语言:javascript
复制
 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

代码语言:javascript
复制
    <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>
EN

回答 10

Stack Overflow用户

发布于 2014-12-19 20:42:10

spring-boot-starter-webspring-boot-starter-actuator中排除logback-classic对我很管用

代码语言:javascript
复制
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"
}
票数 13
EN

Stack Overflow用户

发布于 2016-06-13 14:32:57

将此代码添加到您的build.gradle

代码语言:javascript
复制
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'
}
票数 6
EN

Stack Overflow用户

发布于 2017-02-08 08:20:41

在我的项目中,它使用

  1. spring boot 1.4.2.RELEASE
  2. both slf4j 1.7.21和logback 1.1.7。(一些依赖项,称为模块A,依赖于logback1.1.2,这就是问题所在)

第一个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。问题解决了。

代码语言:javascript
复制
<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>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26061860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档