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

相关推荐
AI+程序员在路上30 分钟前
XML介绍及常用c及c++库
xml·c语言·c++
源码云商2 小时前
【带文档】网上点餐系统 springboot + vue 全栈项目实战(源码+数据库+万字说明文档)
数据库·vue.js·spring boot
zy happy3 小时前
搭建运行若依微服务版本ruoyi-cloud最新教程
java·spring boot·spring cloud·微服务·ruoyi
呦呦彬3 小时前
【问题排查】easyexcel日志打印Empty row!
java·开发语言·log4j
wowocpp4 小时前
spring boot Controller 和 RestController 的区别
java·spring boot·后端
独泪了无痕5 小时前
MongoTemplate 基础使用帮助手册
spring boot·mongodb
炯哈哈6 小时前
【上位机——WPF】App.xml和Application类简介
xml·开发语言·c#·wpf·上位机
獨枭8 小时前
使用 163 邮箱实现 Spring Boot 邮箱验证码登录
java·spring boot·后端
才知山高路远8 小时前
Java - Junit框架
java·junit·log4j
维基框架8 小时前
Spring Boot 封装 MinIO 工具
java·spring boot·后端