解决SLF4J: Class path contains multiple SLF4J bindings.

项目中引入了阿里的datahub依赖,测试时出现一下异常信息:

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/repository/ch/qos/logback/logback-classic/1.2.6/logback-classic-1.2.6.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/repository/org/slf4j/slf4j-log4j12/1.7.32/slf4j-log4j12-1.7.32.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]

发现多个绑定:找到了logback-classic版本1.2.6和slf4j-log4j12版本1.7.32两个绑定。这两个绑定分别用于连接Logback和Log4j这两种不同的日志系统。
实际使用的绑定:尽管存在多个绑定,SLF4J会使用它首先找到的那个,这里就是ch.qos.logback.classic.util.ContextSelectorStaticBinder,意味着实际生效的日志框架是Logback。

解决问题:
1.查看这个依赖里面引入了那些日志框架依赖
2.查看项目中引入的依赖,是否是相同
3.自己项目中没有找到自己配置的和引进依赖里面的相同,那么就是,自己配置其他的依赖里面包含了相同的依赖

对于第3条,就可以选择移除多余的绑定,确保类路径中只保留一个SLF4J的绑定实现。既然实际上使用了Logback,应从项目中移除或排除对slf4j-log4j12依赖。
对于Maven项目,可以在依赖声明中添加排除语句

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
      <exclusions>
          <exclusion>
              <groupId>ch.qos.logback</groupId>
              <artifactId>logback-classic</artifactId>
          </exclusion>
      </exclusions>
</dependency>

我这里移除了 logback-classic 日志实现,以便可以根据项目需求使用其他日志框架。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值