Spring Boot整合Log4j2.xml的问题

文章目录

问题

Spring Boot整合Log4j2.xml的时候返回以下错误:
Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

进行了解决。

解决

Spring Boot整合Log4j2.xml经过以下操作:

  • 配置log4j2.xml
  • 添加到src/main/resources目录下
  • Gradle的配置:在build.gradle中添加:
xml 复制代码
dependencies {
...
    implementation "org.springframework.boot:spring-boot-starter-log4j2"
...
}

启动应用,返回以下错误:
Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

解决方法如下:

我们需要将spring-boot-starter-logging这个模块从所有的库中排除。这里我在build.gradle中使用了以下配置:

xml 复制代码
configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}

再次启动应用,问题解决。

参考

Spring Boot 18.7.2. Configure Log4j for Logging
howtodoinjava: Spring Boot Log4j2.xml Example
Stackoverflow: Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

相关推荐
范什么特西13 分钟前
Spring boot细节
java·spring boot·后端
java1234_小锋1 小时前
请描述 Spring Boot 的启动流程,包括 SpringApplication 的初始化和 run 方法的核心步骤。
java·数据库·spring boot
Flittly2 小时前
【AgentScope Java新手村系列】(9)SpringBoot集成
java·spring boot·spring
杨运交2 小时前
[033][缓存模块]基于 Redisson 的租户隔离 Redis Key 前缀设计
spring boot
星月IWJ3 小时前
idea 工具整理
java·spring boot·intellij-idea
vx-Biye_Design3 小时前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis
霸道流氓气质3 小时前
Spring Boot 微服务性能优化完全指南
spring boot·微服务·性能优化
隔壁阿布都3 小时前
ShedLock 分布式定时任务锁框架介绍
spring boot·分布式
地瓜伯伯4 小时前
从MESI缓存一致性协议讲透synchronized的底层
java·spring boot·spring·spring cloud·微服务·springcloud