SLF4J: Class path contains multiple SLF4J bindings. 问题原因及解决方法。

问题

springboot项目,使用了slf4j,当引入zookeeper之后,就会报错:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/silence.hu/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/silence.hu/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

由问题可以看出,是因为有多种SLFJ实现的绑定:logback-classicslf4j-log4j12 .
因为我是引入zookeeper后才报的错,因此可以肯定是引入zookeeper后才起的jar包冲突,因此将zookeeper中的slf4j-log4j12排除掉就好。


<dependency>
    <groupId>org.apache.zookeepergroupId>
    <artifactId>zookeeperartifactId>
    <exclusions>
        <exclusion>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-log4j12artifactId>
        exclusion>
    exclusions>
dependency>

你可能感兴趣的:(学习日记)