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

  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.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/LenovoSoftstore/softdate/Idealp/.m2/repository/ch/qos/logback/logback-classic/1.2.6/logback-classic-1.2.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 [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (com.health.controller.UserController).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#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并将其删除

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
引用\[1\]和\[2\]中提到了相同的错误信息,即"Class path contains multiple SLF4J bindings"。这个错误通常是由于项目中存在多个SLF4J实现类的绑定引起的。解决这个问题的方法是删除其中一个实现类的依赖。 具体的解决方案如下: 1. 首先,确定你想要使用的SLF4J实现类是哪个。在引用\[1\]中,想要使用的是slf4j-log4j12-1.6.4.jar,而在引用\[2\]中,想要使用的是logback-classic-1.2.3.jar。 2. 打开你的项目的依赖配置文件(比如pom.xml或build.gradle),找到与SLF4J相关的依赖项。 3. 删除其中一个实现类的依赖项。如果你想要使用slf4j-log4j12,那么删除logback-classic的依赖项;如果你想要使用logback-classic,那么删除log4j-slf4j-impl的依赖项。 4. 保存并重新构建你的项目。 这样,你就解决了"Class path contains multiple SLF4J bindings"的问题。请注意,如果你删除了一个实现类的依赖项,你可能需要相应地调整你的日志配置文件,以确保日志记录正常工作。 #### 引用[.reference_title] - *1* [遇到Class path contains multiple SLF4J bindings.该如何解决](https://blog.csdn.net/chuyouyinghe/article/details/79134894)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [SLF4J: Class path contains multiple SLF4J bindings.](https://blog.csdn.net/qq_39323945/article/details/125765205)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Class path contains multiple SLF4J bindings.问题原因解决方案](https://blog.csdn.net/hsuehgw/article/details/128057054)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十一*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值