【BUG】Logging system failed to initialize using configuration from ‘classpath:log4j2-dev.xml’
报错截图:
报错内容:
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:17 - no applicable action for [properties], current ElementPath is [[Configuration][properties]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:33 - no applicable action for [property], current ElementPath is [[Configuration][properties][property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:34 - no applicable action for [property], current ElementPath is [[Configuration][properties][property]]
报错原因分析:jar包存在冲突
查看自己的pom文件是否引入了如下依赖:
<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>
默认引入的logback还有很多的包默认引入的logback包,看下图:
解决办法-1:排除重复引用的 logging
引用(亲测有效)
<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>
备注:pom文件的加载顺序是从上至下执行,将排除logging引用的这一段放在pom引用依赖坐标的首位,这样在向下执行的时候也会排除所有的默认logger了。
解决办法-2:举一反三
排除logging引用的这一段也可以用在其他依赖的引用上,比如我想只导用了web包,不想导入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>