問題
Spring Boot整合Log4j2.xml的時(shí)候返回以下錯(cuò)誤:Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j
進(jìn)行了解決。
解決
Spring Boot整合Log4j2.xml經(jīng)過以下操作:
- 配置
log4j2.xml
- 添加到
src/main/resources
目錄下 - Gradle的配置:在
build.gradle
中添加:
dependencies {
...
implementation "org.springframework.boot:spring-boot-starter-log4j2"
...
}
啟動(dòng)應(yīng)用,返回以下錯(cuò)誤:Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j
解決方法如下:
我們需要將spring-boot-starter-logging
這個(gè)模塊從所有的庫(kù)中排除。這里我在build.gradle
中使用了以下配置:
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
}
再次啟動(dòng)應(yīng)用,問題解決。文章來源:http://www.zghlxwxcb.cn/news/detail-703218.html
參考
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文章來源地址http://www.zghlxwxcb.cn/news/detail-703218.html
到了這里,關(guān)于Spring Boot整合Log4j2.xml的問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!