【Log4j】 SpringBoot项目报错读取两个 StaticLoggerBinder

第一种报错:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.2/log4j-slf4j-impl-2.11.2.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Logging system failed to initialize using configuration from 'classpath:log4j2-dev.xml'
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:17 - no applicable action for [Properties], current ElementPath  is [[configuration][Properties]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@8:35 - no applicable action for [Property], current ElementPath  is [[configuration][Properties][Property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@9:40 - no applicable action for [Property], current ElementPath  is [[configuration][Properties][Property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:41 - no applicable action for [Property], current ElementPath  is [[configuration][Properties][Property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:16 - no applicable action for [appenders], current ElementPath  is [[configuration][appenders]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@15:53 - no applicable action for [console], current ElementPath  is [[configuration][appenders][console]]
  • 重点信息
    SLF4J: Class path contains multiple SLF4J bindings.
    Logback configuration error detected
  • 分析
    仔细看日志,发现日志框架用的是 logback 的包
    SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
    但是项目里配置的Log4j2的配置:
    'classpath:log4j2-dev.xml'
    所以我们需要排除掉 logback ,跑 Log4j2的包

在IDEA的Maven Helper插件中搜索logback的坐标:
在这里插入图片描述
在这里插入图片描述
发现 logback 被包含在 spring-boot-starter-test 中,在POM文件中找到该坐标把 logback 排除即可

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
       <exclusion>
           <artifactId>spring-boot-starter-logging</artifactId>
           <groupId>org.springframework.boot</groupId>
       </exclusion>
    </exclusions>
</dependency>

第二种报错:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.2/log4j-slf4j-impl-2.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/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]
java.lang.StackOverflowError
	at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:108)
	at org.apache.logging.log4j.util.StackLocator.getCallerClass(StackLocator.java:121)
	at org.apache.logging.log4j.util.StackLocatorUtil.getCallerClass(StackLocatorUtil.java:55)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:42)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
  • 重点信息
    SLF4J: Class path contains multiple SLF4J bindings.
    java.lang.StackOverflowError
  • 分析
    这里看报错的日志,发现是加载了两个 slf4j-implLog4jLoggerFactory 所以导致了 StackOverflowError,因此我们需要排除其中的一个 slf4j-impl 的包
    同上面的,在IDEA的Maven Helper插件中搜索slf4j-impl的坐标,然后在POM文件中找到该坐标把 logback 排除即可
<exclusions>
	  <exclusion>
	      <groupId>org.springframework.boot</groupId>
	      <artifactId>spring-boot-starter-log4j2</artifactId>
	  </exclusion>
</exclusions>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值