SLF4J:类路径包含多个 SLF4J 绑定 slf4j-test vs logback-classic
Posted
技术标签:
【中文标题】SLF4J:类路径包含多个 SLF4J 绑定 slf4j-test vs logback-classic【英文标题】:SLF4J: Class path contains multiple SLF4J bindings slf4j-test vs logback-classic 【发布时间】:2018-12-12 10:56:11 【问题描述】:我知道你们都会说什么,这是一个重复的问题,等等……但事实并非如此。因为我已经完成了slf4j-test 中建议的exclusion
配置,所以每当我运行测试时我仍然会收到以下错误:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/C:/Users/admin/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/Users/admin/.m2/repository/uk/org/lidalia/slf4j-test/1.2.0/slf4j-test-1.2.0.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
依赖树告诉我spring-jpa包含ch.qos.logback:logback-classic
依赖。
% mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building weblio-help 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ weblio-help ---
[INFO] jp.weblio.help:weblio-help:jar:1.0.0
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.4.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.5.4.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.4.RELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] | | | \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] \- uk.org.lidalia:slf4j-test:jar:1.2.0:test
[INFO] +- uk.org.lidalia:lidalia-lang:jar:1.0.0:test
[INFO] | \- org.apache.commons:commons-lang3:jar:3.1:test
[INFO] +- com.google.guava:guava:jar:14.0.1:test
[INFO] +- uk.org.lidalia:lidalia-slf4j-ext:jar:1.0.0:test
[INFO] \- joda-time:joda-time:jar:2.9.9:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.845 s
[INFO] Finished at: 2018-07-04T14:07:54+09:00
[INFO] Final Memory: 21M/125M
[INFO] ------------------------------------------------------------------------
我想在测试期间使用slf4j-test
。但似乎即使在包括以下内容之后:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>ch.qos.logback:logback-classic</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
错误仍然存在,似乎 maven-surefire-plugin
类路径排除没有任何效果。我再次看到slf4j-test documentation。
谁能帮我调试一下这个繁琐的错误!!!
【问题讨论】:
【参考方案1】:如果您的 pom 中不需要 logback-classic
依赖项,您可以从 spring-boot-starter-data-jpa 中排除它:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
编辑: 如果您还需要 logback-classic,您可以在 pom 中将其标记为可选:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
【讨论】:
我需要该依赖项才能正常记录。以上是关于SLF4J:类路径包含多个 SLF4J 绑定 slf4j-test vs logback-classic的主要内容,如果未能解决你的问题,请参考以下文章
SLF4J:类路径包含多个 SLF4J 绑定 slf4j-test vs logback-classic
多个 SLF4J 绑定 activemq-all-5.6.0.jar 出错