类路径包含多个SLF4J绑定,log4j-slf4j-impl-2.7.jar,slf4j-log4j12-1.7.21.jar

问题描述 投票:0回答:1

我遇到以下错误。似乎有多个绑定到sl4j的日志记录框架。不确定如何解决此问题。非常感谢您的帮助。

14:42:35,411 ERROR [stderr] (MSC service thread 1-3) SLF4J: Class path contains multiple SLF4J bindings.
14:42:35,412 ERROR [stderr] (MSC service thread 1-3) SLF4J: Found binding in [vfs:/content/offer-warehouse-processor-api.war/WEB-INF/lib/log4j-slf4j-impl-2.7.jar/org/slf4j/impl/StaticLoggerBinder.class]
14:42:35,412 ERROR [stderr] (MSC service thread 1-3) SLF4J: Found binding in [vfs:/content/offer-warehouse-processor-api.war/WEB-INF/lib/slf4j-log4j12-1.7.21.jar/org/slf4j/impl/StaticLoggerBinder.class]
log4j slf4j
1个回答
0
投票

该消息告诉您,您的类路径上同时有slf4j-log4j12-1.7.21.jar和log4j-slf4j-impl-2.7.jar。 slf4j-log4j12将所有SLF4J日志记录路由到log4j 1.2。 Log4j-sfl4j-impl将所有日志记录路由到log4j2。您需要删除不需要的日志。例如,如果要使用log4j 2,则从项目中删除slf4j-log4j12-1.7.21.jar。如果您不确定它是如何包含的,并且您正在使用Maven,请运行

mvn dependency:tree >mvn.txt

然后查看已创建的mvn.txt文件,并从pom.xml中找到该jar所在的位置以及它的依赖关系。然后添加排除项,例如

<exclusions>
  <exclusion>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
</exclusions>

包含它的依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.