我真的很难将logback-classic作为传递依赖问题加载。我遵循stackoverflow上的建议,但是,它会不断重现。
我使用maven exclusions尝试控制它,它在我的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-classic,它正在加载它,如下所示:
<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在依赖项中没有出现:tree
[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 :(得分:3)
Darren Forsythe的评论就是答案。这个-Dincludes = ch.qos.logback:logback-classic允许我找到依赖项。似乎依赖:树搜索只是如此之深。 -Dincludes在完整层次结构中搜索指定的依赖关系。