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

Zah*_*sar 25 java maven

我在编译我的java代码时得到了Exception.请告诉我们如何解决这个冲突.

    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
Run Code Online (Sandbox Code Playgroud)

Wou*_*ter 56

运行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>
Run Code Online (Sandbox Code Playgroud)

  • 这个问题遍布堆栈溢出,但这终于是我需要的东西了! (3认同)
  • 任何使用 IntelliJ 的人都可以使用“Maven”窗口视图来查看包括 log4j 和 slf4j 的依赖项是什么。发现它很有用。 (2认同)
  • @P5Coder 在 IntelliJ 中:查看 -&gt; 工具窗口 -&gt; Maven 项目。 (2认同)

Ang*_*ata 5

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


Bin*_*ati 5

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