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文件

原文地址:https://www.cnblogs.com/wchaos/p/14441419.html