天天看点

springboot项目log4j2启动报错 Logback configuration error detected

  1. 背景

上周换了一台新机器后终于把开发环境配好了,然后本人拉取了当前正在开发的项目和被人的本地分支加载。本来以为可以安心地继续写代码了,不曾想在启动Debug模式时出现了问题。

    2.问题

   项目Debug模式启动时,很快就遇到如图所示的问题:

springboot项目log4j2启动报错 Logback configuration error detected
springboot项目log4j2启动报错 Logback configuration error detected

我的logback配置文件如下:

springboot项目log4j2启动报错 Logback configuration error detected
springboot项目log4j2启动报错 Logback configuration error detected

还有我的项目全局配置文件:

springboot项目log4j2启动报错 Logback configuration error detected
springboot项目log4j2启动报错 Logback configuration error detected

而我的pom文件如图:

<?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">
    <parent>
        <artifactId>fwcloud-provider</artifactId>
        <groupId>com.fwcloud</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>fwcloud-provider-digitalorchard</artifactId>
    <description>苍溪产业园</description>
    <packaging>jar</packaging>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.8.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.4</version>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.8</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
        </dependency>


        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <!--公共应用-->
        <dependency>
            <groupId>com.fwcloud</groupId>
            <artifactId>fwcloud-common-base</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>

        <dependency>
            <groupId>com.fwcloud</groupId>
            <artifactId>fwcloud-activiti5-api</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fwcloud</groupId>
            <artifactId>fwcloud-common-eureka-client</artifactId>
            <!--暂时不注册eureka-->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
            </exclusions>

        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
        </plugins>
        <!--打包包名-->
        <finalName>cx-digitalorchard</finalName>
    </build>
</project>      

   3.解决

springboot项目log4j2启动报错 Logback configuration error detected

其实最开始本人也是遇到问题找度娘,可惜所找到的相关博客和资料并没有提供可行的解决方案。而后,我回顾错误信息,捕捉到如上图的这两行信息。我的新机器只有一个C盘,而错误信息提示很明显了,再到配置信息一看,果然是与错误提示符合。

springboot项目log4j2启动报错 Logback configuration error detected

然后我把配置信息修改如下:

springboot项目log4j2启动报错 Logback configuration error detected

再次启动Debug,运行正常:

springboot项目log4j2启动报错 Logback configuration error detected

    4.总结

   遇到问题找度娘,这不只是一句口头禅或者一个梗,搜素引擎给开发者确实带来了巨大的方便。但是,诚如此次遇到的小问题,其实冷静分析一下错误提示,结合自己近期的情况,其实是可以很快解决的。依赖和思想上的惰性导致一遇到问题就去Ctrl + C,然后Ctrl + v,再回车,以至于忘了自己的大脑其实是最好的工具。感慨如此,以后希望自己引以为戒吧!

logging

  config: classpath:config/logback-dev.xml

  #引入activi

    com:

      fwc

        activiti5: debug

    org:

      activiti: debug

  #文件输入绝对路径

  file: D:/YH/log/fwcloud/@[email protected]

#引入activiti5项目jar的配置

#服务器文件缓存路径

file:

  upload:

    path: D:/YH/upload/@pom.artifact