解決SpringBoot項目中l(wèi)og4j與logback的Jar包沖突問題
異常信息關(guān)鍵詞:
SLF4J: Class path contains multiple SLF4J bindings.
ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:14 - no applicable action for [properties], current ElementPath is [[configuration][properties]]
詳細(xì)異常信息:
Connected to the target VM, address: '127.0.0.1:52687', transport: 'socket' SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/xx/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/xx/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.17.2/log4j-slf4j-impl-2.17.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.xml' java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:14 - no applicable action for [properties], current ElementPath is [[configuration][properties]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@26:29 - no applicable action for [property], current ElementPath is [[configuration][properties][property]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:31 - no applicable action for [property], current ElementPath is [[configuration][properties][property]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@29:33 - no applicable action for [property], current ElementPath is [[configuration][properties][property]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:36 - no applicable action for [property], current ElementPath is [[configuration][properties][property]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:13 - no applicable action for [appenders], current ElementPath is [[configuration][appenders]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@34:47 - no applicable action for [Console], current ElementPath is [[configuration][appenders][Console]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:71 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][appenders][Console][ThresholdFilter]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:44 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][Console][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@47:79 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@48:44 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@49:14 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@53:46 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@56:39 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:11 - no applicable action for [loggers], current ElementPath is [[configuration][loggers]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@61:80 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@62:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@64:109 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@65:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@67:81 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@68:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@71:79 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@72:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@74:71 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@75:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@77:87 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@78:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@80:88 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@81:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@83:80 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@84:77 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@85:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@87:84 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@88:77 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@89:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@92:55 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@93:57 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@94:65 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@95:56 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@96:64 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@97:68 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@98:64 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@99:76 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@100:72 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@101:67 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@102:52 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@103:65 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@104:66 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@105:66 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@106:62 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@107:79 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@110:61 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@111:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@112:29 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][Logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@116:23 - no applicable action for [root], current ElementPath is [[configuration][loggers][root]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@117:33 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@119:29 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179) at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66) at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57) at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132) at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332) at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85) at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66) at java.util.ArrayList.forEach(ArrayList.java:1257)
異常信息告訴我們是jar包沖突導(dǎo)致,解決辦法很簡單,異常信息里面有個官網(wǎng)的地址,說明了解決方式,如下圖:
訪問地址:http://www.slf4j.org/codes.html#multiple_bindings
解決方式是指定使用的jar包,排除另一個不用的即可。
麻煩的是怎么找到導(dǎo)致jar沖突的依賴。
繼續(xù)查看異常信息,提示了沖突的2個jar包的信息,如下截圖:logback-classic和log4j-slf4j-impl。
查找jar依賴關(guān)系可以通過IDEA的maven插件,如下圖直接搜索:
找到了相應(yīng)的依賴包。
也可以通過樹狀結(jié)構(gòu)查看,不如直接搜索來的直觀:
或者通過maven命令查找:
dependency:tree -Dverbose -Dincludes=ch.qos.logback
找到導(dǎo)致沖突的依賴jar包,問題就好解決了,我這里是spring-boot-starter-test包導(dǎo)致的,直接排除springboot自帶的logback即可,clean后運行項目可以正常啟動了。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <!-- 排除自帶的logback依賴 --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
每個項目導(dǎo)致的原因可能各不相同,這是我遇到的一次jar包沖突供參考。
以上就是解決SpringBoot項目中l(wèi)og4j與logback的Jar包沖突問題的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot log4j與logback的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Mybatis-Plus默認(rèn)主鍵策略導(dǎo)致自動生成19位長度主鍵id的坑
這篇文章主要介紹了Mybatis-Plus默認(rèn)主鍵策略導(dǎo)致自動生成19位長度主鍵id的坑,本文一步步給大家分享解決方法,給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-12-12Spring中AOP概念與兩種動態(tài)代理模式原理詳解
AOP是面向切面編程的技術(shù),AOP基于IoC基礎(chǔ),是對OOP的有益補充,流行的AOP框架有Sping AOP、AspectJ,這篇文章主要給大家介紹了關(guān)于Spring中AOP概念與兩種動態(tài)代理模式原理的相關(guān)資料,需要的朋友可以參考下2021-10-10