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

相关推荐
麦兜*1 小时前
Spring Boot启动优化7板斧(延迟初始化、组件扫描精准打击、JVM参数调优):砍掉70%启动时间的魔鬼实践
java·jvm·spring boot·后端·spring·spring cloud·系统架构
KK溜了溜了2 小时前
JAVA-springboot 整合Redis
java·spring boot·redis
大只鹅2 小时前
解决 Spring Boot 对 Elasticsearch 字段没有小驼峰映射的问题
spring boot·后端·elasticsearch
天河归来2 小时前
使用idea创建springboot单体项目
java·spring boot·intellij-idea
IT_10242 小时前
Spring Boot项目开发实战销售管理系统——数据库设计!
java·开发语言·数据库·spring boot·后端·oracle
武昌库里写JAVA3 小时前
Oracle如何使用序列 Oracle序列使用教程
java·开发语言·spring boot·学习·课程设计
超级小忍4 小时前
Spring Boot 中常用的工具类库及其使用示例(完整版)
spring boot·后端
程序员张34 小时前
SQL分析与打印-p6spy组件
spring boot·sql·mybatis·mybatisplus·p6spy
CHENWENFEIc5 小时前
SpringBoot论坛系统安全测试实战报告
spring boot·后端·程序人生·spring·系统安全·安全测试
代码老y7 小时前
Spring Boot + 本地部署大模型实现:优化与性能提升
java·spring boot·后端