maven项目报错:Class path contains multiple SLF4J bindings

时间:2023-03-09 05:18:22
maven项目报错:Class path contains multiple SLF4J bindings

maven项目编译不报错,运行时报错如下:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [bundle://11.0:23/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [bundle://11.0:93/org/slf4j/impl/StaticLoggerBinder.class]

此错误表明:在类路径中有多个SLF4J实现。SLF4J仅允许有一个绑定类,我们需要消除不需要的绑定类,

通过maven命令找到不需要的SLF4J的实现,更新pom.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>
</dependency>