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

相关推荐
困到晕阙3 小时前
[NCTF2019]Fake XML cookbook
xml·xxe
ponnylv4 小时前
深入剖析Spring Boot启动流程
java·开发语言·spring boot·spring
cyforkk5 小时前
Spring Boot @RestController 注解详解
java·spring boot·后端
ruleslol5 小时前
五分钟XML速成
xml
叫我阿柒啊6 小时前
从Java全栈到前端框架:一次真实面试的深度复盘
java·spring boot·typescript·vue·database·testing·microservices
愿你天黑有灯下雨有伞9 小时前
一种基于注解与AOP的Spring Boot接口限流防刷方案
java·spring boot·后端
知识浅谈9 小时前
Redis哨兵模式在Spring Boot项目中的使用与实践
spring boot·redis·bootstrap
lozhyf10 小时前
能发弹幕的简单视频网站
java·spring boot·后端
十八旬11 小时前
苍穹外卖项目实战(day-5完整版)-记录实战教程及问题的解决方法
java·开发语言·spring boot·redis·mysql
chenrui31011 小时前
Spring Boot 和 Spring Cloud: 区别与联系
spring boot·后端·spring cloud