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

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

<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.apache.hadoopgroupId>
			<artifactId>hadoop-commonartifactId>
			<version>2.10.2version>
		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 的依赖关系:
Actual binding is of type [org.slf4j.impl.Reload4jLoggerFactory] 解决方案_第1张图片

如何解决此问题?

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

你可能感兴趣的:(Java,基础,java,intellij-idea,开发语言)