spinrgBoot集成log4j2框架出现多jar错误

springBoot框架集成log4j2框架时,使用idea开发工具,修改pom.xml文件如下:

 1 <!--添加对SpringMVC和Tomcat的依赖-->
 2         <dependency>
 3             <groupId>org.springframework.boot</groupId>
 4             <artifactId>spring-boot-starter-web</artifactId>
 5            <exclusions> <!--去除之前对老版本log4j的依赖-->
 6                <exclusion>
 7                    <artifactId>org.springframework.boot</artifactId>
 8                    <groupId>spring.boot.starter-logging</groupId>
 9                </exclusion>
10            </exclusions>
11         </dependency>
12         <!--添加对日志系统的支持,采用最新的log4j2框架-->
13         <dependency>
14             <groupId>org.springframework.boot</groupId>
15             <artifactId>spring-boot-starter-log4j2</artifactId>
16         </dependency>
View Code

运行程序出现如下错误:

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@4:13 - no applicable action for [appenders], current ElementPath is [configuration]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:47 - no applicable action for [Console], current ElementPath is [configuration[Console]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@8:70 - no applicable action for [ThresholdFilter], current ElementPath is [configurationConsole]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:86 - no applicable action for [PatternLayout], current ElementPath is [configurationConsole]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:59 - no applicable action for [File], current ElementPath is [configuration[File]]
View Code

引用jar时引用了多个logback的框架,由于idea开发工具未根据pom.xml的配置自动配置依赖,未去除之前的log4j的依赖,导致无法解析节点信息。

解决办法:

1、在pom.xml文件中右击选择Diagrams,查看依赖图,找到spring.boot.starter-logging依赖,删除即可。

2、调整<dependency>顺序,pom文件依赖中的顺序问题

在引入的pom坐标下添加了如下排除的依赖。

使用

1 <exclusions>
2     <exclusion>
3         <groupId>包名</groupId>
4         <artifactId>类名</artifactId>
5     </exclusion>
6 </exclusions>

 参考资料:https://www.cnblogs.com/cndarren/p/12054224.html 和   https://blog.csdn.net/pp_fzp/article/details/76157114

原文地址:https://www.cnblogs.com/zl520/p/13321790.html