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

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

<!--添加对SpringMVC和Tomcat的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
           <exclusions> <!--去除之前对老版本log4j的依赖-->
               <exclusion>
                   <artifactId>org.springframework.boot</artifactId>
                   <groupId>spring.boot.starter-logging</groupId>
               </exclusion>
           </exclusions>
        </dependency>
        <!--添加对日志系统的支持,采用最新的log4j2框架-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
运行程序出现如下错误:

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]]
错误原因:

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

解决办法:

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




猜你喜欢

转载自blog.csdn.net/pp_fzp/article/details/76157114