zoukankan      html  css  js  c++  java
  • 启动Spring boot项目报错:java.lang.IllegalArgumentException: LoggerFactory is not a Logback

    java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/D:/develop/apache-maven-3.5.3/repo/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml:

    org.apache.logging.slf4j.Log4jLoggerFactory

    解决:

    在 Spring Boot 中,程序默认使用 Logback 来记录日志并用 INFO 级别输出到控制台,某些情况下我们可能想用其他日志实现框架替换 Logback,在 Spring Boot 中,因为程序使用了自动配置,所以我们可以很方便地替换日志实现,下面以使用 log4j 替换 Logback 为例。

    1. 去除对默认日志的依赖

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

    2. 添加对 log4j 的依赖

    <!-- 添加 log4j 依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
    </dependency>
    

    到此,Spring Boot 项目的日志框架就已经替换成 log4j 了,如需要定义日志输出,只需添加 log4j.properties 文件并在该文件中添加相应配置即可。

  • 相关阅读:
    小技巧
    sql日期函数
    c#发送邮件
    js点滴
    Js序列化时间
    js中string的操作
    原系统中有AD FS , CRM Server ,迁移ADFS 到另一台电脑 , CRM Server用443端口出错
    解决UR 12后ISV目录不能用的问题
    Lucene .Net 版本
    Android 开源项目
  • 原文地址:https://www.cnblogs.com/jiathis/p/11325954.html
Copyright © 2011-2022 走看看