Class path contains multiple SLF4J bindings.问题原因及解决方案

时间:2025-02-12 19:00:31
  1. 问题背景
    在进行logback的日志输出测试时,显示如下错误
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/LenovoSoftstore/softdate/Idealp/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.!/org/slf4j/impl/]
SLF4J: Found binding in [jar:file:/D:/LenovoSoftstore/softdate/Idealp/.m2/repository/ch/qos/logback/logback-classic/1.2.6/logback-classic-1.2.!/org/slf4j/impl/]
SLF4J: See http:///#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org..Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger ().
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See /log4j/1.2/#noconfig for more info.

2、原因
根据上面的错误提示,存在多个SLF4J bindings绑定,即存在多个slf4j的实现类,按上图所示这两个实现分别是logback-classic-1.2.6和slf4j-log4j12-1.6.1,我们需要的是logback而不是log4j,
3、解决方案
因此,我们去掉log4j的依赖就行;查找slf4j-log4j12-1.6.1并将其删除