Logging system failed to initialize using configuration from ‘classpath:log4j2.xml

 引用log4j2报错:Dependency 'org.springframework.boot:spring-boot-starter-log4j2:' not found

 <dependency> <!-- 引入log4j2依赖 -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

一开始是用上面引用,但是项目提示找不到依赖库。然后参考别人改成以下方式。添加成功之后,运行又报错。

   <!-- 2.17.0修复漏洞版本 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.17.0</version>
        </dependency>

报错信息:

在IDEA中,springboot的项目,引入log4j2日志配置时报错:
Logging system failed to initialize using configuration from 'classpath:log4j2.xml'
java.lang.IllegalStateException: Logback configuration error detected: 

分析
配置log4j2.xml文件没有少。

 参考网上说明,主要是sprinpboot原来logback包存在导致冲突,检查包含lib里确实是有logback包。

参考网上的配置,更新pom.xml,更新完成之后,清除一下缓存,重新同步maven相关配置。即可解决问题。

pom.xml 整个源码配置如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.gtk</groupId>
    <artifactId>mbblibser</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.5.6</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>

            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.google.collections</groupId>
            <artifactId>google-collections</artifactId>
            <version>1.0</version>
        </dependency>



        <!-- 2.17.0修复漏洞版本 -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.17.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.17.0</version>
        </dependency>

    </dependencies>


</project>

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用'classpath:log4j2.xml'配置文件时,日志记录系统初始化失败的原因可能有以下几种情况: 1. 配置文件路径错误:请确保'log4j2.xml'文件位于正确的类路径下,即与应用程序的类文件在同一目录或子目录中。 2. 配置文件格式错误:请检查'log4j2.xml'文件的语法和结构是否正确。确保文件中的标签和配置项与日志记录系统的要求一致。 3. 缺少必要的依赖:如果应用程序使用了特定版本的log4j 2.x,需要确保相关的log4j 2.x库已正确添加到项目的依赖中。你可以通过maven资源库或手动添加jar包来解决依赖问题。 4. 日志记录系统版本不匹配:请确保你正在使用与'log4j2.xml'配置文件相对应的log4j版本。不同版本的log4j可能有不兼容的配置项或语法。 综上所述,当出现'Logging system failed to initialize using configuration from 'classpath:log4j2.xml''的错误时,你可以检查配置文件的路径、格式,以及相关的依赖和日志记录系统的版本是否正确。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Logging system failed to initialize using configuration from 'classpath:logback.xml'](https://blog.csdn.net/qq_43648299/article/details/103832227)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [logging-log4j2-log4j-2.15.0-rc2.zip maven 资源库](https://download.csdn.net/download/u010569806/72510733)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值