项目启动:SLF4J: Class path contains multiple SLF4J bindings. 没有日志内容输出

错误内容如下所示:

Connected to the target VM, address: '127.0.0.1:64443', transport: 'socket'
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/corey/develope/maven/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/corey/develope/maven/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.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]
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 

原因:一个接口,被两个实现类实现了。然后,程序在启动获取时,只想获取一个。
这个接口是:org.apache.logging.slf4j.Log4jLoggerFactory
两个实现类分别是:

ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder

org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class

查看:idea中 command + O 查看;然后输入StaticLoggerBinder,即可定位到两个实现类。然后在实现类中,按alt + f1 再回车,便可以定位到引用的包。

定位两个包如下:

和:

发现两个实现类,都是maven替我们引入的,所以需要在maven的配置文件上下手,排除一个。

因为我是引入zookeeper后才报的错,因此可以肯定是引入zookeeper后才起的jar包冲突,因此将zookeeper中的slf4j-log4j12排除掉就好。

<!--zookeeper-->
<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions>
</dependency>

然后查看command + o 查看依赖:

启动项目正常启动。。。。

 

 
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页