slf4j的多个绑定和不匹配版本

时间:2017-01-24 15:13:30

标签: logging slf4j logback-classic

我正在尝试使用slf4j-api和log4j-over-slf4j,但我遇到了以下警告

System.err: SLF4J: Class path contains multiple SLF4J bindings.
System.err: SLF4J: Found binding in [jar:file:/E:/developer/NewSandbox/MY_DEV_GRID_1/grid/applications/webproject/appdata/webapps/webproject-0.1.0/WEB-INF/lib/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
System.err: SLF4J: Found binding in [jar:file:/E:/developer/NewSandbox/MY_DEV_GRID_1/runtimes/2.0.20161021-083156/services/log/slf4j-grid-2.0.20161021-083156.jar!/org/slf4j/impl/StaticLoggerBinder.class]
System.err: SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
System.err: SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
System.err: SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.

我试图了解这些多重绑定的来源。如果我将logback-classic排除在spring-boot-starter-logging之外,我会收到如下链接错误

loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" 

这是我通过gradle for slf4j-api的依赖树

org.slf4j:slf4j-api:1.7.21 (selected by rule)
+--- org.slf4j:jcl-over-slf4j:1.7.21
|    +--- org.springframework.data:spring-data-redis:1.7.6.RELEASE
|    |    +--- compile
|    |    \--- project :common
|    |         \--- compile
|    +--- org.springframework.data:spring-data-keyvalue:1.1.5.RELEASE
|    |    \--- org.springframework.data:spring-data-redis:1.7.6.RELEASE (*)
|    +--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE
|    |    \--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.2.RELEASE
|    |         \--- compile
|    +--- org.springframework.boot:spring-boot-starter-logging:1.4.2.RELEASE
|    |    \--- org.springframework.boot:spring-boot-starter:1.4.2.RELEASE
|    |         +--- org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE
|    |         |    \--- compile
|    |         +--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.2.RELEASE (*)
|    |         +--- org.springframework.boot:spring-boot-starter-jersey:1.4.2.RELEASE
|    |         |    \--- compile
|    |         +--- org.springframework.boot:spring-boot-starter-aop:1.4.2.RELEASE
|    |         |    \--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.2.RELEASE (*)
|    |         +--- org.springframework.boot:spring-boot-starter-jdbc:1.4.2.RELEASE
|    |         |    \--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.2.RELEASE (*)
|    |         \--- org.springframework.boot:spring-boot-starter-validation:1.4.2.RELEASE
|    |              \--- org.springframework.boot:spring-boot-starter-jersey:1.4.2.RELEASE (*)
|    \--- org.springframework.data:spring-data-commons:1.12.5.RELEASE
|         +--- org.springframework.data:spring-data-keyvalue:1.1.5.RELEASE (*)
|         \--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE (*)
+--- org.slf4j:jul-to-slf4j:1.7.21
|    \--- org.springframework.boot:spring-boot-starter-logging:1.4.2.RELEASE (*)
+--- org.slf4j:log4j-over-slf4j:1.7.21
|    \--- org.springframework.boot:spring-boot-starter-logging:1.4.2.RELEASE (*)
+--- org.springframework.data:spring-data-commons:1.12.5.RELEASE (*)
+--- org.springframework.data:spring-data-jpa:1.10.5.RELEASE (*)
\--- org.springframework.data:spring-data-keyvalue:1.1.5.RELEASE (*)

org.slf4j:slf4j-api:1.6.1 -> 1.7.21
+--- org.apache.bval:bval-core:0.3-incubating
|    +--- org.apache.bval:org.apache.bval.bundle:0.3-incubating
|    |    \--- org.apache.openjpa:openjpa-maven-plugin:2.4.1
|    |         \--- compile
|    \--- org.apache.bval:bval-jsr303:0.3-incubating
|         \--- org.apache.bval:org.apache.bval.bundle:0.3-incubating (*)
\--- org.apache.bval:bval-jsr303:0.3-incubating (*)

org.slf4j:slf4j-api:1.6.3 -> 1.7.21
+--- io.swagger:swagger-core:1.5.0
|    \--- io.swagger:swagger-jaxrs:1.5.0
|         \--- io.swagger:swagger-jersey2-jaxrs:1.5.0
|              \--- compile
\--- io.swagger:swagger-models:1.5.0
     \--- io.swagger:swagger-core:1.5.0 (*)

org.slf4j:slf4j-api:1.7.5 -> 1.7.21
\--- com.microsoft.azure:adal4j:1.0.0
     \--- com.microsoft.azure:azure-keyvault:0.9.3
          \--- com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8
               \--- compile

org.slf4j:slf4j-api:1.7.12 -> 1.7.21
\--- project :common
     \--- compile

org.slf4j:slf4j-api:1.7.20 -> 1.7.21
\--- ch.qos.logback:logback-classic:1.1.7
     \--- org.springframework.boot:spring-boot-starter-logging:1.4.2.RELEASE
          \--- org.springframework.boot:spring-boot-starter:1.4.2.RELEASE
               +--- org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE
               |    \--- compile
               +--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.2.RELEASE
               |    \--- compile
               +--- org.springframework.boot:spring-boot-starter-jersey:1.4.2.RELEASE
               |    \--- compile
               +--- org.springframework.boot:spring-boot-starter-aop:1.4.2.RELEASE
               |    \--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.2.RELEASE (*)
               +--- org.springframework.boot:spring-boot-starter-jdbc:1.4.2.RELEASE
               |    \--- org.springframework.boot:spring-boot-starter-data-jpa:1.4.2.RELEASE (*)
               \--- org.springframework.boot:spring-boot-starter-validation:1.4.2.RELEASE
                    \--- org.springframework.boot:spring-boot-starter-jersey:1.4.2.RELEASE (*)

org.slf4j:slf4j-api:1.7.22 -> 1.7.21
\--- org.springframework.data:spring-data-redis:1.7.6.RELEASE
     +--- compile
     \--- project :common
          \--- compile

不确定我还应该尝试解决这些警告

1 个答案:

答案 0 :(得分:4)

就我而言,额外配置来自Apache Spark。按如下方式添加Spark依赖项:

<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.11</artifactId>
    <version>2.0.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

解决了这个问题。我怎么认为这有点问题。我没有太多依赖项,因此我将exclusions添加到每个依赖项中并逐个删除。希望它有所帮助。