2017-04-10 201 views
3

我真的掙扎的logback經典的傳遞依賴問題的加載。我遵循這裏在stackoverflow上找到的建議,但它不斷重複發生。明確的答案

我用maven排除嘗試,試圖控制它,它不會在我的POM依賴層次結構都出現。但它仍然被加載!

這裏是我的運行時跟蹤

SLF4J: Class path contains multiple SLF4J bindings. 
SLF4J: Found binding in [jar:file:/home/david/.m2/repository/de/ruedigermoeller/kontraktor-http/3.33/kontraktor-http-3.33.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: Found binding in [jar:file:/home/david/.m2/repository/ch/qos/logback/logback-classic/1.2.1/logback-classic-1.2.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. 
W 13:22:24:837 : DispatcherThread 1 : DispatcherThread : 
java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getLoggerFactoryClassStr()Ljava/lang/String; 
at org.slf4j.LoggerFactory.reportActualBinding(LoggerFactory.java:271) 
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:143) 
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120) 
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331) 
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283) 
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304) 
at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:284) 
at org.quartz.impl.StdSchedulerFactory.getDefaultScheduler(StdSchedulerFactory.java:1539) 
at uk.co.example.ExampleEwsService.init(ExampleEwsService.java:296) 

部分的問題是,Kontraktor框架覆蓋StaticLoggerBinder.getLoggerFactoryClassStr方法。但它很容易,以確保它被加載,然後再排除的logback經典的石英,這是加載它,如下所示:

<dependency> 
     <groupId>org.quartz-scheduler</groupId> 
     <artifactId>quartz</artifactId> 
     <version>2.2.3</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>slf4j-api</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.quartz-scheduler</groupId> 
     <artifactId>quartz-jobs</artifactId> 
     <version>2.2.3</version> 
    </dependency> 

此時SLF4J只由kontraktor加載。 logback-classic在依賴關係中無處可見:樹

[INFO] +- de.ruedigermoeller:kontraktor:jar:3.33:compile 
[INFO] | +- org.jctools:jctools-core:jar:1.0:compile 
[INFO] | \- de.ruedigermoeller:fst:jar:2.44.5:compile 
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.5.3:compile 
[INFO] |  +- org.javassist:javassist:jar:3.19.0-GA:compile 
[INFO] |  +- org.objenesis:objenesis:jar:2.1:compile 
[INFO] |  \- com.cedarsoftware:java-util:jar:1.9.0:compile 
[INFO] |  \- com.cedarsoftware:json-io:jar:2.5.1:compile 
[INFO] +- de.ruedigermoeller:kontraktor-http:jar:3.33:compile 
[INFO] | +- io.github.lukehutch:fast-classpath-scanner:jar:1.2.3:compile 
[INFO] | +- org.apache.httpcomponents:httpasyncclient:jar:4.1:compile 
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile 
[INFO] | | +- org.apache.httpcomponents:httpcore-nio:jar:4.4.1:compile 
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.4.1:compile 
[INFO] | | | \- commons-codec:commons-codec:jar:1.9:compile 
[INFO] | | \- commons-logging:commons-logging:jar:1.2:compile 
[INFO] | +- javax.websocket:javax.websocket-api:jar:1.1:compile 
[INFO] | +- io.undertow:undertow-core:jar:1.2.8.Final:compile 
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.1.4.GA:compile 
[INFO] | | +- org.jboss.xnio:xnio-api:jar:3.3.1.Final:compile 
[INFO] | | \- org.jboss.xnio:xnio-nio:jar:3.3.1.Final:runtime 
[INFO] | +- io.undertow:undertow-websockets-jsr:jar:1.2.8.Final:compile 
[INFO] | | +- io.undertow:undertow-servlet:jar:1.2.8.Final:compile 
[INFO] | | | +- org.jboss.spec.javax.servlet:jboss-servlet-api_3.1_spec:jar:1.0.0.Final:compile 
[INFO] | | | \- org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:jar:1.0.0.Final:compile 
[INFO] | | \- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.0.Final:compile 
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.12:compile 
[INFO] | \- org.jsoup:jsoup:jar:1.8.2:compile 
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.5:compile 
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.5:compile 
[INFO] +- org.quartz-scheduler:quartz:jar:2.2.3:compile 
[INFO] | \- c3p0:c3p0:jar:0.9.1.1:compile 
[INFO] +- org.quartz-scheduler:quartz-jobs:jar:2.2.3:compile 

這麼簡單的問題,logback-classic如何加載以及誰加載它?

+0

日誌顯示,你還有你的classpath的logback經典-1.2.1.jar。也許試試mvn clean,或者ide中的clean命令可以解決這個問題。 – Solo

+0

都嘗試MVN全新安裝和Maven清潔套裝,不改變結果。我知道這是在我的班級路徑中,我需要找到的是誰在那裏包括它。 – csDave

+1

嘗試其他選項與依賴目標,並尋找具體的依賴?例如 'MVN依賴性:樹-Dincludes = org.slf4j:SLF4J-api' –

回答

3

由達倫·科西的註釋就是答案。這-Dincludes = ch.qos.logback:logback-classic允許我找到依賴關係。看起來,依賴:樹搜索只是如此之深。 -Dincludes在完整的層次結構中搜索指定的依賴關係。