完美解決Logback configuration error detected的問(wèn)題
今天在springboot項(xiàng)目中替換log4j2日志的時(shí)候遇見(jiàn)的問(wèn)題,閑話不多說(shuō)。
錯(cuò)誤日志
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@3:16 - no applicable action for [appenders], current ElementPath is [[configuration][appenders]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:67 - no applicable action for [Console], current ElementPath is [[configuration][appenders][Console]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][Console][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:119 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:23 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:45 - no applicable action for [TimeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][TimeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:57 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:48 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@21:79 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@23:23 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:45 - no applicable action for [TimeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][TimeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@25:57 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@27:48 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:79 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][appenders][RollingFile][ThresholdFilter]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:14 - no applicable action for [loggers], current ElementPath is [[configuration][loggers]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@36:64 - no applicable action for [logger], current ElementPath is [[configuration][loggers][logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@39:44 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:77 - no applicable action for [logger], current ElementPath is [[configuration][loggers][logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@44:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@50:28 - no applicable action for [root], current ElementPath is [[configuration][loggers][root]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@52:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@53:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@54:44 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162) at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66) at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56) at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114) at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:309) at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:277) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325) at org.springframework.boot.SpringApplication.run(SpringApplication.java:296) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:121) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189) at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter@3:16 - no applicable action for [appenders], current ElementPath is [[configuration][appenders]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:67 - no applicable action for [Console], current ElementPath is [[configuration][appenders][Console]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][Console][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:119 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:23 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:45 - no applicable action for [TimeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][TimeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:57 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:48 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@21:79 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@23:23 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:45 - no applicable action for [TimeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][TimeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@25:57 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@27:48 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:79 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][appenders][RollingFile][ThresholdFilter]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:14 - no applicable action for [loggers], current ElementPath is [[configuration][loggers]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@36:64 - no applicable action for [logger], current ElementPath is [[configuration][loggers][logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@39:44 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:77 - no applicable action for [logger], current ElementPath is [[configuration][loggers][logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@44:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@50:28 - no applicable action for [root], current ElementPath is [[configuration][loggers][root]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@52:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@53:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@54:44 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:316) at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:277) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240) at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325) at org.springframework.boot.SpringApplication.run(SpringApplication.java:296) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:121) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) ... 24 more Caused by: java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter@3:16 - no applicable action for [appenders], current ElementPath is [[configuration][appenders]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:67 - no applicable action for [Console], current ElementPath is [[configuration][appenders][Console]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][Console][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:119 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:23 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:45 - no applicable action for [TimeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][TimeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:57 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:48 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@21:79 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:96 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@23:23 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:45 - no applicable action for [TimeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][TimeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@25:57 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@27:48 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:79 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][appenders][RollingFile][ThresholdFilter]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:14 - no applicable action for [loggers], current ElementPath is [[configuration][loggers]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@36:64 - no applicable action for [logger], current ElementPath is [[configuration][loggers][logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@39:44 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:77 - no applicable action for [logger], current ElementPath is [[configuration][loggers][logger]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@44:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][logger][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@50:28 - no applicable action for [root], current ElementPath is [[configuration][loggers][root]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@52:42 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@53:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@54:44 - no applicable action for [appender-ref], current ElementPath is [[configuration][loggers][root][appender-ref]] at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162) at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66) at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56) at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114) at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:309) ... 38 more Disconnected from the target VM, address: '127.0.0.1:65035', transport: 'socket' Process finished with exit code -1
首先我們看上面的錯(cuò)誤日志
Logging system failed to initialize using configuration from 'classpath:log4j2-dev.xml' java.lang.IllegalStateException: Logback configuration error detected:
如果只看這兩句的話我們可能會(huì)認(rèn)為是我們的日志文件log4j2-dev.xml配置錯(cuò)了,或者路徑找不到,其實(shí)不然。正解是我們pom文件配置的有問(wèn)題,jar包存在沖突,下面來(lái)看下我們的pom文件吧
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>
上面的pom文件是最初報(bào)錯(cuò)時(shí)的配置文件,看上面的配置文件貌似沒(méi)有問(wèn)題,我們需使用log4j2日志的starter也已經(jīng)引入了,但是這里我們需要注意一點(diǎn)就是我們?cè)谝雜pring-boot-starter-web包的時(shí)候他里面默認(rèn)使用了logback日志,這樣就會(huì)產(chǎn)生日志包的沖突,其實(shí)不只是starter-web包默認(rèn)引入的logback還有很多的包默認(rèn)引入的logback包,看下圖
上圖中是這個(gè)pom文件的jiar包結(jié)構(gòu)示意圖,log4j2部分就是我們新引入的spring-boot-starter-log4j2包,上圖中我通過(guò)黃線畫出了現(xiàn)在系統(tǒng)中所有l(wèi)ogback的引入,可以看出所有引用,這里涉及到幾個(gè)包,分別是web包,mybatis包,jdbc包。那我們現(xiàn)在要解決jar包沖突的問(wèn)題是不是需要每個(gè)包下都排除默認(rèn)引用的logger日志呢,理論上是完全沒(méi)有問(wèn)題的,但是那樣豈不是很費(fèi)事,2種解決辦法。
解決辦法1
統(tǒng)一排除
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
解決辦法2
那我只導(dǎo)用了web包,不想導(dǎo)入spring-boot-starter能不能解決呢?
答 : 能
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency>
看見(jiàn)第二個(gè)解決辦法,問(wèn)題是不是來(lái)了。很多包都默認(rèn)使用的logback,你單獨(dú)排除了web包是不是還會(huì)出現(xiàn)這個(gè)問(wèn)題,
答 : 是的會(huì)出現(xiàn),這里就需要知道pom文件的加載順序了,pom文件的加載順序也是從上至下執(zhí)行,那么我們就需要把web包放到pom文件中的第一位,在向下執(zhí)行的時(shí)候也會(huì)排除所有的默認(rèn)logger了。
上面就是兩種解決辦法。希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java如何發(fā)起http請(qǐng)求的實(shí)現(xiàn)(GET/POST)
這篇文章主要介紹了Java如何發(fā)起http請(qǐng)求的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03Spring?Boot自動(dòng)配置的原理及@Conditional條件注解
這篇文章主要介紹了Spring?Boot自動(dòng)配置的原理及@Conditional條件注解,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的朋友可以參考一下2022-07-07JAVA中List.addAll的基本語(yǔ)法與用法詳解
這篇文章主要給大家介紹了關(guān)于JAVA中List.addAll的基本語(yǔ)法與用法的相關(guān)資料,需要的朋友可以參考下2024-06-06Java設(shè)計(jì)模式之單態(tài)模式(Singleton模式)介紹
這篇文章主要介紹了Java設(shè)計(jì)模式之單態(tài)模式(Singleton模式)介紹,本文講解了如何使用單例模式、使用單例模式注意事項(xiàng)等內(nèi)容,需要的朋友可以參考下2015-03-03SpringBoot使用 druid 連接池來(lái)優(yōu)化分頁(yè)語(yǔ)句
這篇文章主要介紹了SpringBoot使用 druid 連接池來(lái)優(yōu)化分頁(yè)語(yǔ)句,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11