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

  • 相关阅读:
    JAVA之代理2CGLib
    Java并发编程:Lock
    synchronized详解
    redis哨兵机制--配置文件sentinel.conf详解
    redis.conf讲解
    [Java并发包学习八]深度剖析ConcurrentHashMap
    [Java并发包学习七]解密ThreadLocal
    T和Class以及Class的理解
    python学习笔记十:异常
    python学习笔记九:正则表达式
  • 原文地址:https://www.cnblogs.com/wchaos/p/14441419.html
Copyright © 2020-2023  润新知