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中添加:
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中使用了以下配置:
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
到此这篇关于Spring Boot整合Log4j2.xml的问题的文章就介绍到这了,更多相关Spring Boot整合Log4j2.xml内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Java中system.exit(0) 和 system.exit(1)区别
本文主要介绍了Java中system.exit(0) 和 system.exit(1)区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2023-05-05
Springboot与vue实例讲解实现前后端分离的人事管理系统
这篇文章主要介绍了如何用Java实现企业人事管理系统,文中采用springboot+vue实现前后端分离,感兴趣的小伙伴可以学习一下2022-06-06


最新评论