java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > idea项目启动报错,日志包冲突slf4j和logback冲突

idea项目启动报错,日志包冲突slf4j和logback冲突问题

作者:郝猿

遇到SLF4J冲突时,可以尝试移除冲突的绑定或调整项目依赖,具体方法包括删除多余的Logger绑定库,如Logback或Log4j,或在项目配置文件中明确指定使用的日志框架,若使用WebLogic服务器,需在weblogic.xml中进行特定配置,适当调整pom.xml文件中的依赖版本也可能解决问题

idea项目启动报错,日志包冲突slf4j和logback冲突

报错如下

SLF4J: Found binding in [jar:file:/E:/maven_dev/maven_3/apache-maven-3.5.2/repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/E:/maven_dev/maven_3/apache-maven-3.5.2/repo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/StaticLoggerBinder.class] Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/E:/maven_dev/maven_3/apache-maven-3.5.2/repo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory

SLF4J: Found binding in [jar:file:/E:/maven_dev/maven_3/apache-maven-3.5.2/repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/maven_dev/maven_3/apache-maven-3.5.2/repo/org/slf4j/slf4j-log4j12/1.7.29/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/StaticLoggerBinder.class]

在pom.xml中添加

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!--解决日志包冲突-->
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

根据自己的版本进行调整

<!--添加zookeeper版本,与虚拟机一致-->
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.9</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

启动ok!!!

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文