Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/wangxue/maven/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/wangxue/maven/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.nstl.ncloud.OAuthApplication.main(OAuthApplication.java:16)
Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j
springcloud项目本身需要spring-boot-starter-web包,我又额外用了spring-boot-starter-log4j2。运行时一直报以下的错误,一开始以为是spring-boot-starter-web与spring-cloud-starter-gateway冲突了,实际这俩不在同一个微服务里面是不会冲突的。
最后发现是spring-boot-starter冲突了,我开始是没有引入的,是spring-boot-starter-web自带的。

解决:引入spring-boot-starter包,而且要放在spring-boot-starter-web前面,有个顺序问题。

这样我的情况就解决了!
本文解决了一个关于Log4j与SLF4J在Spring Boot项目中出现的冲突问题,详细介绍了错误信息及解决步骤。通过调整依赖引入顺序,成功解决了log4j-slf4j-impl与log4j-to-slf4j同时存在导致的问题。
5109

被折叠的 条评论
为什么被折叠?



