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

相关推荐
是梦终空13 小时前
计算机源码273—基于SpringBoot+Vue3停车场管理系统带支沙箱支付(源代码+数据库)
数据库·spring boot·vue·mybatis·停车场管理系统·沙箱支付·毕设设计
Filwaod13 小时前
Java面试:AIGC场景下的技术深度拷问-谢飞机篇
spring boot·缓存·微服务·消息队列·aigc·java面试·ai技术
隐退山林14 小时前
JavaEE进阶:SpringBoot配置文件
java·spring boot·java-ee
霸道流氓气质16 小时前
SpringAI+Ollama本地模型实现快速对话入门实例
spring boot·ai
xun-ming17 小时前
SpringBoot和Vue3实战阿里百炼大模型极简版
spring boot·ai·vue3·智能体·百炼大模型
csdn2015_17 小时前
java springboot 文件导入,判断第一列的值是否有重复
java·windows·spring boot
阿丰资源17 小时前
基于Springboot+mysql的在线兼职平台(附源码)
spring boot·后端·mysql
怪祝浙17 小时前
从简单项目入手Java(学生系统)V6(Web版本 Spring Boot3 MySQL Vue3 MyBatis)
java·spring boot·mysql
蜡台19 小时前
Vue + SpringBoot 实现 WebSocket 基于 Sec-WebSocket-Protocol 传参鉴权(避坑指南)
vue.js·spring boot·websocket·sec