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测试框架详解
java·spring boot·后端
程序员小凯2 小时前
Spring Boot缓存机制详解
spring boot·后端·缓存
程序媛徐师姐4 小时前
Java基于SpringBoot的茶叶商城系统,附源码+文档说明
java·spring boot·java springboot·茶叶商城系统·java茶叶商城系统·茶叶·java茶叶商城
Lucky_Turtle4 小时前
【Java Xml】Apache Commons Digester3解析
xml·java·apache
计算机毕业设计木哥5 小时前
计算机毕业设计选题推荐:基于SpringBoot和Vue的快递物流仓库管理系统【源码+文档+调试】
java·vue.js·spring boot·后端·课程设计
Chan169 小时前
流量安全优化:基于 Sentinel 实现网站流量控制和熔断
java·spring boot·安全·sentinel·intellij-idea·进程
莫陌尛.9 小时前
xml 方式声明式事务案例
xml
勇往直前plus9 小时前
如何利用docker部署springboot应用
spring boot·docker·容器
ZhengEnCi10 小时前
@RequestParam 注解完全指南-从参数绑定到接口调用的Web开发利器
java·spring boot
=>>漫反射=>>10 小时前
单元测试 vs Main方法调试:何时使用哪种方式?
java·spring boot·单元测试