Log4j 无法启动spring启动服务器
我是spring boot新手,当我尝试启动服务器时,出现以下异常。我知道这与依赖冲突有关,但仍然无法解决。我正在使用maven管理我的依赖项。请帮助Log4j 无法启动spring启动服务器,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 c
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>
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
spring启动程序日志记录
org.springframework.boot
spring-boot-starter-log4j
最终解决了这个问题,排除了Logback依赖项,并明确添加了log4j依赖项排除了spring boot starter web中的Logback classic,并且spring boot starter执行器对我有效
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"
}
将此添加到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'
}
在我的项目中,它使用
<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>
回写
回归经典
1.1.2
回写
回溯堆芯
1.1.2
回写
回写访问
1.1.2
Gradle解决方案正在build.Gradle中添加以下行:
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
我的gradle.build文件中的以下配置适用于我:
configurations {
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
all*.exclude group: "ch.qos.logback"
all*.exclude group: "org.slf4j", module: "log4j-over-slf4j" // allow using log4j 2.x
all*.exclude group: "org.slf4j", module: "slf4j-simple" // log4j is the configured backend
}
我建议您尝试删除任何包含Logback的依赖项,最常见的是:
org.springframework.boot
spring-boot-starter-log4j2
这对我来说很有效。重复回答,但您可以使用Eclipse排除spring boot starter日志依赖项
如果在类路径上,Spring Boot支持Log4j 2进行日志配置。如果使用启动器组装依赖项,则必须排除Logback,然后包含log4j 2 通过按此顺序添加以下依赖项解决了此问题
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<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>
org.springframework.boot
spring-boot-starter-log4j2
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
spring启动程序日志记录
您能否提供您的pom.xml
?您好,最后通过排除Logback依赖项并显式添加log4j依赖项解决了这个问题。很高兴听到您解决了这个问题。回答你自己的问题没有坏处:你应该把你的解决方案作为答案贴出来,然后接受它。我对Spring Boot做了一个改进,这样它就可以确定竞争对手LoggerFactory实现的来源,并希望使问题更容易诊断:Andy,gr8。。。谢谢你,我知道这是一个老问题,但为了未来的读者:记住“mvn依赖:树”任务是你的朋友。它需要一些工作——例如,您必须认识到org.slf4j:slf4j simple与logback冲突——但是当遇到这个问题时(通常是由于可传递的依赖关系)以树状形式查看依赖项通常会使我找到解决方案的路径。您能分享gradle更改吗?我可以确认这很有帮助。适用于我的gradle配置与上面提到的相同。配置{all*.exclude group:“org.springframework.boot”,模块:“spring boot starter logging”all*.exclude group:“ch.qos.logback”all*.exclude group:“org.slf4j simple”//log4j是配置的后端}谢谢你,伙计,其他解决方案不起作用,但明确定义了!