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

相关推荐
怒放吧德德15 分钟前
Spring Boot实战:Event事件机制解析与实战
java·spring boot·后端
㳺三才人子39 分钟前
SpringDoc OpenAPI 配置問題
服务器·spring boot
yoyo_zzm1 小时前
SpringBoot Test详解
spring boot·后端·log4j
zuowei28892 小时前
Spring BOOT 启动参数
java·spring boot·后端
阿亮爱学代码2 小时前
初识Android界面布局
android·xml·view·viewgroup
tycooncool2 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
一 乐2 小时前
房产租赁管理|基于springboot + vue房产租赁管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·房产租赁管理系统
未秃头的程序猿2 小时前
从零到一:深入浅出分布式锁原理与Spring Boot实战(Redis + ZooKeeper)
spring boot·分布式·后端
慕容卡卡3 小时前
你所不知道的RAG那些事
java·开发语言·人工智能·spring boot·spring cloud
程序员萌萌3 小时前
基于 Redis 的分布式锁:原理剖析与 Spring Boot 实战(含看门狗续期)
spring boot·redis·分布式锁·看门狗机制