SLF4J: Class path contains multiple SLF4J bindings.解决方案

SLF4J: Class path contains multiple SLF4J bindings.解决方案

错误日志信息:

SLF4J: Found binding in [jar:file:/usr/local/src/hadoop/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hbase/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.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]

image-20211104165053564

含义为:
发生jar包冲突了:
分别为:
:file:/usr/local/src/hadoop/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar
:file:/usr/local/hbase/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.jar
移除其中一个jar包即可
解决方案:
使用下面命令:
/usr/local/hbase/lib rm slf4j-log4j12-1.7.25.jar
关闭命令窗口重新运行

Linux上,如果遇到`SLF4J: Class path contains multiple SLF4J bindings`这样的错误,通常意味着你的项目中引入了多个日志框架,如logback和slf4j本身的jar包,它们试图竞争作为默认的日志管理器。解决这个问题需要确保只有一个SLF4J绑定被有效加载。这里有一些步骤可以帮助你: 1. **查看依赖**:首先,检查你的Maven或Gradle构建文件,确认是否有多个SLF4J相关的依赖项。移除多余的、未使用的库。 ```bash mvn dependency:tree | grep slf4j ``` 或者 ```bash gradle dependencies | grep slf4j ``` 2. **保留一个版本**:选择一个你喜欢的日志框架,例如slf4j本身或logback,并将其作为项目的主要日志库。删除其他版本。 3. **排除冲突**:在build.gradle或pom.xml文件中,对slf4j的依赖添加exclusions,明确指定排除其他冲突的版本。 例如,在Gradle中: ```groovy dependencies { implementation 'org.slf4j:slf4j-api:1.x.y' implementation 'org.slf4j:slf4j-log4j12:1.x.y' // 或者 logback-classic implementation 'ch.qos.logback:logback-core:1.x.y' implementation 'ch.qos.logback:logback-classic:1.x.y' exclude group: 'org.slf4j', module: 'slf4j-log4j12' // 或者exclude org.slf4j:slf4j-jdk14 } ``` 4. **配置桥接器**:如果你同时使用slf4j-api和logback-classic,可能需要在应用启动时添加一个BridgeHandler,确保两者能正常协同工作。比如在Spring Boot中,可以这样做: ```java import org.slf4j.bridge.SLF4JBridgeHandler; SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); ``` 5. **重启项目**:最后,清理并重新构建项目,然后重启应用程序以加载新的配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

java厂长

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

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

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

打赏作者

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

抵扣说明:

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

余额充值