log4j - 无法启动Spring Boot服务器

标签 log4j spring-boot

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

最佳答案

spring-boot-starter-webspring-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"
}

关于log4j - 无法启动Spring Boot服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26061860/

相关文章:

java - log4j异常处理

java - Log4J 能够从磁盘已满中恢复吗?

log4j - 如何使用自定义的log4j.xml在netty中配置记录器?

grails - 如何使用 Log4J 禁用来自不同模块的日志记录,例如阻止 'Resources' 的日志

java - 多个 Spring Boot 应用程序

mysql - SQL查找属于圆的坐标

log4j - 如何从 log4j 堆栈跟踪中过滤某些行?

spring-boot - 如何在IntelliJ IDEA社区中使Spring Boot的自动重启工作? (出/建目录问题)

使用表单主体的 Spring MVC Controller 方法映射

java - 来自 application.properties 的 Spring Boot 配置