第一种报错:
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-impl
的Log4jLoggerFactory
所以导致了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>