报错 SLF4J: Class path contains multiple SLF4J bindings. 导致项目日志不打印

1 篇文章 0 订阅
1 篇文章 0 订阅

问题:

项目启动时报错如下:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/G:/demo/log-loader-demo/target/log-loader-demo/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/G:/demo/log-loader-demo/target/log-loader-demo/WEB-INF/lib/slf4j-log4j12-1.6.6.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

解决方案:

1、需要清楚想使用哪种日志工具,log4j 还是 logback ?

2、查看maven依赖树,到项目的pom.xml文件夹所在目录,执行命令: 

mvn dependency:tree

如果是idea,可以从底部 Terminal 执行

3、在依赖树结果中搜索你想去除的日志工具依赖,此处我想去除 log4j

查询到 simpleimage 依赖了 log4jslf4j-log4j12,导致启动时与 logback 冲突

4、去除多余的依赖

<dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>simpleimage</artifactId>
      <version>1.2.3</version>
      <!-- 去除log4j相关依赖,防止与logback冲突 -->
      <exclusions>
        <exclusion>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
      </exclusions>
</dependency>

5、一定要保证依赖中不再含有 log4j 依赖,可以再次执行第二步的步骤进行排查,最终项目启动时,应该不会再报这个错误。

问题排查思路:

1、查看 第四行的提示 http://www.slf4j.org/codes.html#multiple_bindings

发现文中有处理方案(下图上传后变形了,查看时可以点击下放大查看)

 

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值