Actual binding is of type [org.slf4j.impl.Reload4jLoggerFactory] 解决方案

在升级Hadoop-Common从2.7.2到2.10.2后,遇到SLF4J多个绑定冲突的错误。错误原因是类路径中存在多个SLF4J实现,导致日志桥接器冲突。解决方法是在POM文件中使用<exclusions>标签排除slf4j-reload4j依赖,或者在<dependencyManagement>标签内直接对hadoop-common的依赖进行排除。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近项目修复安全漏洞,需要升级 hadoop-common 版本,从 2.7.2 升级到 2.10.2 版本。
升级一般通常是在 父类工程 使用 <dependencyManagement> 标签限制版本号,如下:

<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.apache.hadoop</groupId>
			<artifactId>hadoop-common</artifactId>
			<version>2.10.2</version>
		</dependency>
		...
	</dependencies>
</dependencyManagement>

结果运行工程,出现 如下错误:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/.m2/repository/org/slf4j/slf4j-reload4j/1.7.36/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.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.Reload4jLoggerFactory]
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Reload4jLoggerFactory loaded from file:/C:/Users/.m2/repository/org/slf4j/slf4j-reload4j/1.7.36/slf4j-reload4j-1.7.36.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Reload4jLoggerFactory

产生这个错误的原因是在产生日志信息的时候有两个桥接器,发生冲突导致error。

通过 mvn dependency:tree 查看依赖关系, 确认发现 : slf4j-reload4j 桥接器在前面,取代 logback-classic

这里最直观是使用 idea 工具查看 pom 的依赖关系:
在这里插入图片描述

如何解决此问题?

  1. 可以找到指定依赖地方使用 ,剔除即可
<exclusions>
	<exclusion>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-reload4j</artifactId>
	</exclusion>
</exclusions>
  1. 第2种类同上面,在 <dependencyManagement> 标签限制版本号 直接使用 <exclusions> , 如下:
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.apache.hadoop</groupId>
			<artifactId>hadoop-common</artifactId>
			<version>2.10.2</version>
			<exclusions>
				<exclusion>
					<groupId>org.slf4j</groupId>
					<artifactId>slf4j-reload4j</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		...
	</dependencies>
</dependencyManagement>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值