springboot項目報錯解決:ERROR StatusLogger No Log4j 2 configuration file found


springboot項目報錯:ERROR StatusLogger No Log4j 2 configuration file found

問題描述

spring boot項目,識別不了log4j2.yml配置文件,報如下錯誤:

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

很明顯,錯誤顯示找不到log4j2的配置文件,但是resources目標下,確定是有該文件的。

初步判斷是依賴問題,導致沒有讀取到配置文件。

解決方案:

<dependencies>
		<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>
       
        <!-- 配置 log4j2 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
        <!-- 加上這個才能辨認到log4j2.yml文件 -->
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
        </dependency>
       <!-- 加上這個,上面那個包才能正常工作 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson-databind-version}</version>
        </dependency>
</dependencies>

總結:

1、首先引入spring-boot包,去掉其中默認的logback包

2、引入spring-boot-starter-log4j2包,配置log4j2

3、加上jackson-databind和jackson-dataformat-yaml才能正常識別log4j2.yml文件


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM