SLF4J: Class path contains multiple SLF4J bindings

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SLF4J: Class path contains multiple SLF4J bindings相关的知识,希望对你有一定的参考价值。

参考技术A springboot log4j2 报错SLF4J: Class path contains multiple SLF4J bindings,maven依赖重复冲突的解决办法

springboot 使用log4j保存日志,网上随便找了篇博文参考,配置依赖照写,启动结果报错: Class path contains multiple SLF4J bindings
具体报错如下:

报错字面意思 有多个 SLF4J 绑定,log4j-slf4j-impl-2.11.2.jar 和 logback-classic-1.2.3.jar里面重复绑定SLF4J ,再看了下那博文,有这么一段,如项目中有导入spring-boot-starter-web依赖包记得去掉spring自带的日志依赖spring-boot-starter-logging,如下:

按上面说法是 spring-boot-starter-web 自带日志依赖,那既然exclusion排除了日志依赖咋还有问题!

实际是 spring-boot-starter 自带日志依赖 而不是 spring-boot-starter-web,下面才是正确的

比如 这里要搜索的是 logback-classic-1.2.3.jar 在哪里被依赖
在上面打开的依赖关系图中 crtl + f 打开搜索,然后输入搜索内容 logback-classic,如下:
点击找到的logback-classic ,会看到如下依赖关系:

那就在pom.xml中用排除掉,
如下:

其他类似的maven 重复依赖问题,可以按上面方法尝试去解决!

Maven中日志jar包冲突报错:Class path contains multiple SLF4J bindings

错误表现:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/learn/Java/maven/repository_taotao/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/learn/Java/maven/repository_taotao/org/apache/activemq/activemq-all/5.11.2/activemq-all-5.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

控制台报错如下图所示:

 

错误原因:
发生jar包冲突了:
分别为:

SLF4J: Found binding in [jar:file:/D:/learn/Java/maven/repository_taotao/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/learn/Java/maven/repository_taotao/org/apache/activemq/activemq-all/5.11.2/activemq-all-5.11.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]

解决方案:

 

可以转到pom.xml,打开Dependency Hierarchy并找到slf4j条目。除了通过右键单击“exclude maven artifact”排除其余条目。

运行mvn dependency:tree并搜索哪些依赖项具有slf4j您不想要的实现,然后使用依赖项排除将其排除,例如:

        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>
        <!-- 配置对ActiveMQ客户端的依赖jar包 -->
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
        </dependency>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

以上是关于SLF4J: Class path contains multiple SLF4J bindings的主要内容,如果未能解决你的问题,请参考以下文章

SLF4J: Class path contains multiple SLF4J bindings.警告解决

SLF4J: Class path contains multiple SLF4J bindings.

spark 与 Hadoop 融合后启动 slf4j提示Class path contains multiple SLF4J bindings

Hive客户端启动报SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Class path contains multiple SLF4J bindings.——Hbase启动输出

SLF4J: Class path contains multiple SLF4J bindings.——Hive启动输出