问题描述
我在 Spring Boot 应用程序中出现以下错误:
I have the following error in spring boot application:
SLF4J:类路径包含多个 SLF4J 绑定.SLF4J:在 [jar:file:/opt/tomcat/webapps/ROOT/WEB-INF/lib/slf4j-simple-1.7.13.jar!/org/slf4j/impl/StaticLoggerBinder.class] 中找到绑定SLF4J:在 [jar:file:/opt/tomcat/webapps/ROOT/WEB-INF/lib/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] 中找到绑定SLF4J:参见 http://www.slf4j.org/codes.html#multiple_bindings一个解释.
SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in [jar:file:/opt/tomcat/webapps/ROOT/WEB-INF/lib/slf4j-simple-1.7.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: Found binding in [jar:file:/opt/tomcat/webapps/ROOT/WEB-INF/lib/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
我转到链接并尝试从 pom 中删除 slf4j-simple-1.7.13 和 logback-classic,我认为这是导入它,但没有用.
I went to the link and tried to remove slf4j-simple-1.7.13 and logback-classic from the pom I thought was importing this but it did not work.
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solrj.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
和
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solrj.version}</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
Solr J 版本:
<solrj.version>5.2.1</solrj.version>
我如何确定这是否是正确的违规模块?是不是我做错了什么?
How can I determine if this is the correct offending module? Is there something I'm doing incorrectly?
pom 文件使用了我们自己创建的 spring boot parent.也许这就是需要排除的地方?
The pom file uses a spring boot parent we created ourselves. Maybe that is where the exclusions need to take place?
这是 org.slf4j 的依赖树:
Here is the dependency tree for org.slf4j:
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ some-service ---
[INFO] com.company.io.some.service:some-service:war:1.0.0-SNAPSHOT
[INFO] +- com.company.io.commons:commons-mongo:jar:1.0.0:compile
[INFO] | \- com.company.io.commons:discovery-schema:jar:1.0.0:compile
[INFO] | +- com.company.io.commons:commons-schema:jar:1.0.0:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.6; omitted for duplicate)
[INFO] | +- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] | +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] | | \- (org.com.company.io:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] | \- com.company.io.commons:commons-utils:jar:1.0.0:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.6; omitted for duplicate)
[INFO] +- org.apache.solr:solr-solrj:jar:5.2.1:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.13:compile
[INFO] +- de.flapdoodle.embed:de.flapdoodle.embed.mongo:jar:1.50.5:test
[INFO] | \- de.flapdoodle.embed:de.flapdoodle.embed.process:jar:1.50.2:test
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:test - version managed from 1.7.10; omitted for duplicate)
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.3.0.RELEASE:compile
[INFO] | \- org.springframework.boot:spring-boot-starter:jar:1.3.0.RELEASE:compile
[INFO] | \- org.springframework.boot:spring-boot-starter-logging:jar:1.3.0.RELEASE:compile
[INFO] | +- org.slf4j:jcl-over-slf4j:jar:1.7.13:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.10; omitted for duplicate)
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.13:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.10; omitted for duplicate)
[INFO] | \- org.slf4j:log4j-over-slf4j:jar:1.7.13:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.10; omitted for duplicate)
[INFO] +- com.company.io.spring.boot.starter:central-config-spring-boot-starter:jar:1.0.0:compile
[INFO] | +- com.company.io.config:config-client:jar:1.0.0:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] | +- io.springfox:springfox-swagger-ui:jar:2.2.2:compile
[INFO] | | \- io.springfox:springfox-spring-web:jar:2.2.2:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] | \- io.springfox:springfox-swagger2:jar:2.2.2:compile
[INFO] | +- io.swagger:swagger-models:jar:1.5.3:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.6.3; omitted for duplicate)
[INFO] | +- io.springfox:springfox-spi:jar:2.2.2:compile
[INFO] | | \- io.springfox:springfox-core:jar:2.2.2:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] | +- io.springfox:springfox-swagger-common:jar:2.2.2:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] | +- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] | +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.10; omitted for duplicate)
[INFO] | +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.10; omitted for duplicate)
[INFO] | \- org.springframework.hateoas:spring-hateoas:jar:0.19.0.RELEASE:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] +- com.company.io.spring.boot.starter:ana-spring-boot-starter:jar:1.0.0:compile
[INFO] | \- com.company.io.auth:ana-client:jar:1.2.0:compile
[INFO] | +- com.company.io.commons:commons-jersey:jar:1.0.0:compile
[INFO] | | \- com.company.io.commons:rules-schema:jar:1.0.0:compile
[INFO] | | +- com.company.io.commons:event-schema:jar:1.0.0:compile
[INFO] | | | +- com.company.io.commons:data-schema:jar:1.0.0:compile
[INFO] | | | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.6; omitted for duplicate)
[INFO] | | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.6; omitted for duplicate)
[INFO] | | +- com.company.io.commons:notification-schema:jar:1.0.0:compile
[INFO] | | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.6; omitted for duplicate)
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.6; omitted for duplicate)
[INFO] | +- com.company.io.commons:commons-statsd:jar:1.0.0:compile
[INFO] | | +- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] | | \- org.slf4j:slf4j-simple:jar:1.7.13:compile (version managed from 1.7.12)
[INFO] | | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.12; omitted for duplicate)
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] \- io.company.on.spring.boot.starter:metrics-spring-boot-starter:jar:1.0.0:compile
[INFO] +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] +- io.dropwizard.metrics:metrics-annotation:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] +- io.dropwizard.metrics:metrics-healthchecks:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] +- io.dropwizard.metrics:metrics-json:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] +- io.dropwizard.metrics:metrics-jvm:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] +- io.dropwizard.metrics:metrics-servlet:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] +- io.dropwizard.metrics:metrics-servlets:jar:3.1.2:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.7; omitted for duplicate)
[INFO] \- com.ryantenney.metrics:metrics-spring:jar:3.0.4:compile
[INFO] \- (org.slf4j:slf4j-api:jar:1.7.13:compile - version managed from 1.7.5; omitted for duplicate)
推荐答案
您是否尝试过在 POM 中为 org.slf4j:slf4j-simple
添加排除项,例如:
Have you tried adding an exclusion for org.slf4j:slf4j-simple
in your POM, for example:
<dependency>
<groupId>com.company.io.spring.boot.starter</groupId>
<artifactId>ana-spring-boot-starter</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
这篇关于SLF4J的多重绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!