繁体   English   中英

Maven SLF4J:类路径包含多个SLF4J绑定

[英]Maven SLF4J: Class path contains multiple SLF4J bindings

我在运行我的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

运行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>

看来你有几个SLF4J的实现; 你应该排除所有不必要的

此错误意味着您在类路径中有多个SLF4J实现。 查看错误具体说明的内容。 即: SLf4J: Found binding in..... (这将打印它找到StaticLoggerBinder.class实例的所有jar文件)。 消除类路径中的所有这些jar,除了你需要StaticLoggerBinder.class实现的jar。

这个作品!! 更新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> 

您可以转到POM.xml,打开依赖关系层次结构并找到slf4j条目。除了通过右键单击“排除maven工件”排除其余部分

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM