Java Maven SLF4J:类路径包含多个 SLF4J 绑定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22896243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven SLF4J: Class path contains multiple SLF4J bindings
提问by Zahid Nisar
I am getting following runtime Exception while running my java code. Could someone please help me resolve the binding conflicts.
我在运行我的 Java 代码时遇到运行时异常。有人可以帮我解决绑定冲突。
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-android-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-jcl-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-nop-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Air/Desktop/sms/slf4j-1.7.7/slf4j-simple-1.7.7.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.AndroidLoggerFactory]
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Fatal error in constructor!
... 2 more
采纳答案by Wouter
Run mvn dependency:tree
and search which dependency have the slf4j
implementations you do not want, then excludethem with a dependency exclusion like:
运行mvn dependency:tree
并搜索哪些依赖项具有slf4j
您不想要的实现,然后使用依赖项排除项排除它们,例如:
<dependency>
<groupId>org.someexternallib</groupId>
<artifactId>someexternallibartifact</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
回答by Angelo Immediata
It seems you have several implementation of SLF4J; you should exclude all the not necessary ones
看来你有几个 SLF4J 的实现;你应该排除所有不必要的
回答by Binita Bharati
This error means that you have multiple implementations of SLF4J in your classpath.
Look for what the errors are specifically saying. i.e :
SLf4J: Found binding in.....
(This will print all the jar files where it found instances of StaticLoggerBinder.class). Eliminate all such jars from your classpath, except the jar whose StaticLoggerBinder.class implementation you need.
此错误意味着您的类路径中有多个 SLF4J 实现。查找错误具体说的是什么。即:(
SLf4J: Found binding in.....
这将打印所有找到 StaticLoggerBinder.class 实例的 jar 文件)。从您的类路径中删除所有此类 jar,除了您需要其 StaticLoggerBinder.class 实现的 jar。
回答by Atul Yadav
You can go to POM.xml , open Dependency Hierarchy and find slf4j entries.Except one exclude rest of them by right clicking "exclude maven artifact"
您可以转到 POM.xml ,打开 Dependency Hierarchy 并找到 slf4j 条目。通过右键单击“排除 maven 工件”排除其余条目
回答by Akitha_MJ
This Works !! Update the porm.xml
这有效!!更新 porm.xml
<dependency>
<groupId>org.someexternallib</groupId>
<artifactId>someexternallibartifact</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>