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

Logging slf4j的多个绑定和不匹配版本,logging,slf4j,logback-classic,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

我试图使用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.
我试图理解这些多个绑定来自何处。如果我通过
spring boot starter日志记录排除
logback classic
,我会得到如下链接错误

loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" 
这是我通过gradle对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

不确定我还应该尝试什么来解决这些警告在我的情况下,额外的配置来自ApacheSpark。添加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>

org.apache.spark
spark-core_2.11
2.0.1
org.slf4j
slf4j-log4j12

解决了这个问题。但我觉得这有点问题。我没有太多的依赖项,所以我在每个依赖项中添加了
排除项
,并逐个删除。希望有帮助。

在我的例子中,额外的配置来自ApacheSpark。添加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>

org.apache.spark
spark-core_2.11
2.0.1
org.slf4j
slf4j-log4j12
解决了这个问题。但我觉得这有点问题。我没有太多的依赖项,所以我在每个依赖项中添加了
排除项
,并逐个删除。希望能有帮助