如何解决log4j-slf4j-implcannotbepresentwithlog4j-to-slf4j报错
本篇内容介绍了“如何解决log4j-slf4j-impl cannot be present with log4j-to-slf4j报错”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
创新互联是一家专业提供湘西土家族企业网站建设,专注与成都网站制作、成都网站设计、H5建站、小程序制作等业务。10年已为湘西土家族众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。
构建一个项目的时候,启动时候爆了下面的错误:
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/buildSoft/java/maven/jar-center/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:/buildSoft/java/maven/jar-center/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.xt.gateway.GatewayApplication.main(GatewayApplication.java:22) Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j at org.apache.logging.slf4j.Log4jLoggerFactory.validateContext(Log4jLoggerFactory.java:49) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:39) at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:30) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:54) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363) at org.apache.commons.logging.LogAdapter$Slf4jAdapter.createLocationAwareLog(LogAdapter.java:130) at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:91) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59) at org.springframework.boot.SpringApplication.(SpringApplication.java:196) ... 1 more
因为项目 spring boot 默认 使用 logback ,但是我这里 指定了 log4j2
org.springframework.boot spring-boot-starter-log4j2
解决办法
只需要 对因此的 spring boot starter 对应依赖排除对应的 log 依赖即可
org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-logging org.springframework.cloud spring-cloud-starter-gateway org.springframework.boot spring-boot-starter-logging org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-logging
“如何解决log4j-slf4j-impl cannot be present with log4j-to-slf4j报错”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
当前文章:如何解决log4j-slf4j-implcannotbepresentwithlog4j-to-slf4j报错
浏览路径:http://pwwzsj.com/article/ighdhe.html