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

相关推荐
vx-Biye_Design16 分钟前
SSM伴侣动物伴护星小程序06330-计算机课程设计、毕业设计
spring boot·后端·elasticsearch·小程序·架构·课程设计·idea
前端精髓8 小时前
NestJS 是什么(对着 Spring Boot 一起学习)
spring boot·后端·学习
武哥聊编程10 小时前
【AI实战项目】基于SpringAI+Springboot+Vue的AI面试刷题训练平台
vue.js·人工智能·spring boot·springai
vipxieliang10 小时前
固定电话验证详解:区号、号码、分机号的完整验证
java·spring boot
步行cgn10 小时前
Spring Boot 主入口类上的 @Enable 和 @Scan 注解详解
java·spring boot·后端
xixingzhe211 小时前
SpringBoot DDD 实战入门文档
spring boot·spring·ddd
杨运交13 小时前
[069][公共模块]Spring Boot 全局异常处理与参数校验实战(下):校验异常精细化处理与 WebFlux 适配
java·spring boot·后端
行者-全栈开发13 小时前
Spring Boot + FFmpeg 视频批量处理实战:压缩、HLS切片与异步任务引擎
spring boot·ffmpeg·异步处理·视频压缩·hls切片·批量任务·redis队列
Andya_net13 小时前
Spring Boot | 条件注解完全指南:从 @Conditional 到 @ConditionalOnExpression 的原理、实践与避坑
spring boot·后端·python
小荷才露尖尖角,早有蜻蜓立上头14 小时前
class java.util.LinkedHashMap cannot be cast to xxx
java·spring boot