ClassCastException org.[=10th=] 无法转换为 ch.qos.logback.classic.LoggerContext
ClassCaseException org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
A type incompatibility occurred while executing com.cerner.clinicaldev:gatling-plugin:1.0.0-SNAPSHOT:run: org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
我正在编写一个 maven mojo,它启动 Jetty 实现并以编程方式运行 Gatling。我试过从 io.gatling:gatling-app:2.2.5 中排除 slf4j 并在 maven-enforcer-plugin 中作为被禁止的依赖项包括在内都没有用。
我在包含它的依赖关系树中看不到任何其他地方;
+- io.gatling:gatling-app:jar:2.2.5:compile
| +- io.gatling:gatling-core:jar:2.2.5:compile
| | +- io.gatling:gatling-commons:jar:2.2.5:compile
| | | +- com.typesafe:config:jar:1.3.1:compile
| | | +- com.dongxiguo:fastring_2.11:jar:0.2.4:compile
| | | +- com.softwaremill.quicklens:quicklens_2.11:jar:1.4.8:compile
| | | +- org.asynchttpclient:async-http-client-netty-utils:jar:2.0.29:compile
| | | +- com.typesafe.scala-logging:scala-logging_2.11:jar:3.5.0:compile
| | | \- ch.qos.logback:logback-classic:jar:1.1.7:compile
| | | \- ch.qos.logback:logback-core:jar:1.1.7:compile
| | +- com.typesafe.akka:akka-actor_2.11:jar:2.4.12:compile
| | +- com.typesafe.akka:akka-slf4j_2.11:jar:2.4.12:compile
| | +- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.8.4:compile
| | | +- com.fasterxml.jackson.core:jackson-core:jar:2.8.4:compile
| | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
| | +- me.chrons:boopickle_2.11:jar:1.2.4:compile
| | +- org.scala-lang.modules:scala-java8-compat_2.11:jar:0.8.0-RC7:compile
| | +- com.github.ben-manes.caffeine:caffeine:jar:2.3.5:compile
| | +- com.github.scopt:scopt_2.11:jar:3.5.0:compile
| | +- io.gatling:jsonpath_2.11:jar:0.6.8:compile
| | +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.4:compile
| | +- io.advantageous.boon:boon-json:jar:0.6.6:compile
| | | \- io.advantageous.boon:boon-reflekt:jar:0.6.6:compile
| | +- net.sf.saxon:Saxon-HE:jar:9.7.0-10:compile
| | \- org.jodd:jodd-lagarto:jar:3.8.0:compile
| | +- org.jodd:jodd-core:jar:3.8.0:compile
| | \- org.jodd:jodd-log:jar:3.8.0:compile
| +- io.gatling:gatling-http:jar:2.2.5:compile
| | +- org.asynchttpclient:async-http-client:jar:2.0.29:compile
| | | +- io.netty:netty-codec-http:jar:4.0.44.Final:compile
| | | | +- io.netty:netty-codec:jar:4.0.44.Final:compile
| | | | \- io.netty:netty-handler:jar:4.0.44.Final:compile
| | | +- org.asynchttpclient:netty-resolver-dns:jar:2.0.29:compile
| | | | +- org.asynchttpclient:netty-resolver:jar:2.0.29:compile
| | | | \- org.asynchttpclient:netty-codec-dns:jar:2.0.29:compile
| | | +- org.reactivestreams:reactive-streams:jar:1.0.0:compile
| | | +- com.typesafe.netty:netty-reactive-streams:jar:1.0.8:compile
| | | \- org.javassist:javassist:jar:3.21.0-GA:compile
| | \- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.0.44.Final:compile
| | +- io.netty:netty-common:jar:4.0.44.Final:compile
| | +- io.netty:netty-buffer:jar:4.0.44.Final:compile
| | \- io.netty:netty-transport:jar:4.0.44.Final:compile
| +- io.gatling:gatling-jms:jar:2.2.5:compile
| | \- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
| +- io.gatling:gatling-jdbc:jar:2.2.5:compile
| +- io.gatling:gatling-redis:jar:2.2.5:compile
| | \- net.debasishg:redisclient_2.11:jar:3.2:compile
| +- io.gatling:gatling-metrics:jar:2.2.5:compile
| | \- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
| \- io.gatling:gatling-charts:jar:2.2.5:compile
| \- com.tdunning:t-digest:jar:3.1:compile
+- io.spray:spray-json_2.11:jar:1.3.3:compile
+- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
+- javax.ws.rs:jsr311-api:jar:1.1.1:compile
+- org.apache.maven:maven-plugin-api:jar:3.5.0:compile
| +- org.apache.maven:maven-model:jar:3.5.0:compile
| | +- org.codehaus.plexus:plexus-utils:jar:3.0.24:compile
| | \- org.apache.commons:commons-lang3:jar:3.5:compile
| +- org.apache.maven:maven-artifact:jar:3.5.0:compile
| \- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.3:compile
| +- javax.enterprise:cdi-api:jar:1.0:compile
| | +- javax.annotation:jsr250-api:jar:1.0:compile
| | \- javax.inject:javax.inject:jar:1:compile
| +- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.3:compile
| +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
| \- org.codehaus.plexus:plexus-classworlds:jar:2.5.2:compile
+- org.eclipse.jetty.aggregate:jetty-all-server:jar:8.2.0.v20160908:compile
| +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile
| +- org.eclipse.jetty.orbit:javax.security.auth.message:jar:1.0.0.v201108011116:compile
| +- org.eclipse.jetty.orbit:javax.mail.glassfish:jar:1.4.1.v201005082020:compile
| +- org.eclipse.jetty.orbit:javax.activation:jar:1.1.0.v201105071233:compile
| \- org.eclipse.jetty.orbit:javax.annotation:jar:1.1.0.v201108011116:compile
+- org.scala-lang:scala-library:jar:2.11.8:compile
+- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.5:provided
+- org.scalatest:scalatest_2.11:jar:3.0.3:test
| +- org.scalactic:scalactic_2.11:jar:3.0.3:test
| +- org.scala-lang:scala-reflect:jar:2.11.8:compile
| +- org.scala-lang.modules:scala-xml_2.11:jar:1.0.5:compile
| \- org.scala-lang.modules:scala-parser-combinators_2.11:jar:1.0.4:compile
\- org.specs2:specs2-core_2.11:jar:2.5:test
\- org.specs2:specs2-matcher_2.11:jar:2.5:test
\- org.specs2:specs2-common_2.11:jar:2.5:test
+- org.scalaz:scalaz-core_2.11:jar:7.2.0:test
\- org.scalaz:scalaz-concurrent_2.11:jar:7.2.0:test
\- org.scalaz:scalaz-effect_2.11:jar:7.2.0:test
我已经尝试了 3 天来解决这个问题。
补充一下...这是 JDK1.8 和 Maven 3.3.9。
求助!?!
编辑::
如果我在我的 mojo class 头部显式实例化一个记录器,我会得到以下堆栈跟踪:
com.google.inject.ProvisionException:无法配置,看到以下错误:
1) Error injecting constructor, java.lang.ClassCastException:
org.slf4j.impl.SimpleLoggerFactory cannot be cast to
ch.qos.logback.classic.LoggerContext at
com.cerner.clinicaldev.gatlingplugin.GatlingPlugin.(Unknown
Source) while locating
com.cerner.clinicaldev.gatlingplugin.GatlingPlugin
1 error at
com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1025)
at
com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
at
org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClass.java:48)
at
com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
at
com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:53)
at
com.google.inject.internal.ProviderInternalFactory.call(ProviderInternalFactory.java:65)
at
com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:115)
at
org.eclipse.sisu.bean.BeanScheduler$Activator.onProvision(BeanScheduler.java:176)
at
com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:126)
at
com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:68)
at
com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:63)
at
com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:45)
at
com.google.inject.internal.InjectorImpl.call(InjectorImpl.java:1016)
at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at
com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1012)
at org.eclipse.sisu.inject.Guice4.get(Guice4.java:162) at
org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:81)
at
org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51)
at
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:263)
at
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:255)
at
org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:517)
at
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:121)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at
org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at
org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at
org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at
org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) at
org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at
org.apache.maven.cli.MavenCli.main(MavenCli.java:199) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.ClassCastException:
org.slf4j.impl.SimpleLoggerFactory cannot be cast to
ch.qos.logback.classic.LoggerContext at
com.cerner.clinicaldev.gatlingplugin.GatlingPlugin.(GatlingPlugin.scala:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at
com.google.inject.internal.DefaultConstructionProxyFactory.newInstance(DefaultConstructionProxyFactory.java:86)
at
com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
at
com.google.inject.internal.ConstructorInjector.access[=14=]0(ConstructorInjector.java:32)
at
com.google.inject.internal.ConstructorInjector.call(ConstructorInjector.java:89)
at
com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:115)
at
com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:133)
at
com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:68)
at
com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:87)
at
com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at
com.google.inject.internal.InjectorImpl.call(InjectorImpl.java:1016)
at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at
com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1012)
尝试添加以下依赖项,其中包括 logback-classic
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
它包含在
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
将你的记录器初始化为你 class :-
private static final Logger logger = LoggerFactory.getLogger(DemoClass.class)
最后,我将maven-plugin和gatling项目分离出来,并从其他依赖中排除了slfj。
我在 Play Framework 中遇到了类似的问题:
我唯一要做的就是将 Provided
添加到依赖项中。
这是我的案例 SBT:
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.26" % Provided,
我的标准错误有:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/wf/.m2/repository/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/wf/.m2/repository/ch/qos/logback/logback-classic/1.1.5/logback-classic-1.1.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
指向 http://www.slf4j.org/codes.html#multiple_bindings,它建议将排除项添加到不需要的绑定中。所以我做了一个
mvn dependency:tree | grep -B1 -C1 logback
显示例如
[INFO] +- nl.vaneijndhoven.dukes:rc-watchdog:jar:0.0.2:compile
[INFO] \- ch.qos.logback:logback-classic:jar:1.1.5:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.1.5:compile
[INFO] \- org.slf4j:slf4j-api:jar:1.7.16:compile
虽然有更新版本的 logback-classic:
https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.2.3
在我的 eclipse 工作区的 pomfiles 中的版本号 1.7.25 和 1.7.21 之后,我发现我直接使用 vert.x 作为依赖项目(用于调试目的)。当我从构建路径中删除该项目时,我很好。
所以一般的方法是查看你的依赖关系
mvn dependency:tree
并将 slf4j 从冲突的依赖项中排除或将它们一起删除。
A type incompatibility occurred while executing com.cerner.clinicaldev:gatling-plugin:1.0.0-SNAPSHOT:run: org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
我正在编写一个 maven mojo,它启动 Jetty 实现并以编程方式运行 Gatling。我试过从 io.gatling:gatling-app:2.2.5 中排除 slf4j 并在 maven-enforcer-plugin 中作为被禁止的依赖项包括在内都没有用。
我在包含它的依赖关系树中看不到任何其他地方;
+- io.gatling:gatling-app:jar:2.2.5:compile
| +- io.gatling:gatling-core:jar:2.2.5:compile
| | +- io.gatling:gatling-commons:jar:2.2.5:compile
| | | +- com.typesafe:config:jar:1.3.1:compile
| | | +- com.dongxiguo:fastring_2.11:jar:0.2.4:compile
| | | +- com.softwaremill.quicklens:quicklens_2.11:jar:1.4.8:compile
| | | +- org.asynchttpclient:async-http-client-netty-utils:jar:2.0.29:compile
| | | +- com.typesafe.scala-logging:scala-logging_2.11:jar:3.5.0:compile
| | | \- ch.qos.logback:logback-classic:jar:1.1.7:compile
| | | \- ch.qos.logback:logback-core:jar:1.1.7:compile
| | +- com.typesafe.akka:akka-actor_2.11:jar:2.4.12:compile
| | +- com.typesafe.akka:akka-slf4j_2.11:jar:2.4.12:compile
| | +- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.8.4:compile
| | | +- com.fasterxml.jackson.core:jackson-core:jar:2.8.4:compile
| | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
| | +- me.chrons:boopickle_2.11:jar:1.2.4:compile
| | +- org.scala-lang.modules:scala-java8-compat_2.11:jar:0.8.0-RC7:compile
| | +- com.github.ben-manes.caffeine:caffeine:jar:2.3.5:compile
| | +- com.github.scopt:scopt_2.11:jar:3.5.0:compile
| | +- io.gatling:jsonpath_2.11:jar:0.6.8:compile
| | +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.4:compile
| | +- io.advantageous.boon:boon-json:jar:0.6.6:compile
| | | \- io.advantageous.boon:boon-reflekt:jar:0.6.6:compile
| | +- net.sf.saxon:Saxon-HE:jar:9.7.0-10:compile
| | \- org.jodd:jodd-lagarto:jar:3.8.0:compile
| | +- org.jodd:jodd-core:jar:3.8.0:compile
| | \- org.jodd:jodd-log:jar:3.8.0:compile
| +- io.gatling:gatling-http:jar:2.2.5:compile
| | +- org.asynchttpclient:async-http-client:jar:2.0.29:compile
| | | +- io.netty:netty-codec-http:jar:4.0.44.Final:compile
| | | | +- io.netty:netty-codec:jar:4.0.44.Final:compile
| | | | \- io.netty:netty-handler:jar:4.0.44.Final:compile
| | | +- org.asynchttpclient:netty-resolver-dns:jar:2.0.29:compile
| | | | +- org.asynchttpclient:netty-resolver:jar:2.0.29:compile
| | | | \- org.asynchttpclient:netty-codec-dns:jar:2.0.29:compile
| | | +- org.reactivestreams:reactive-streams:jar:1.0.0:compile
| | | +- com.typesafe.netty:netty-reactive-streams:jar:1.0.8:compile
| | | \- org.javassist:javassist:jar:3.21.0-GA:compile
| | \- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.0.44.Final:compile
| | +- io.netty:netty-common:jar:4.0.44.Final:compile
| | +- io.netty:netty-buffer:jar:4.0.44.Final:compile
| | \- io.netty:netty-transport:jar:4.0.44.Final:compile
| +- io.gatling:gatling-jms:jar:2.2.5:compile
| | \- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
| +- io.gatling:gatling-jdbc:jar:2.2.5:compile
| +- io.gatling:gatling-redis:jar:2.2.5:compile
| | \- net.debasishg:redisclient_2.11:jar:3.2:compile
| +- io.gatling:gatling-metrics:jar:2.2.5:compile
| | \- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
| \- io.gatling:gatling-charts:jar:2.2.5:compile
| \- com.tdunning:t-digest:jar:3.1:compile
+- io.spray:spray-json_2.11:jar:1.3.3:compile
+- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
+- javax.ws.rs:jsr311-api:jar:1.1.1:compile
+- org.apache.maven:maven-plugin-api:jar:3.5.0:compile
| +- org.apache.maven:maven-model:jar:3.5.0:compile
| | +- org.codehaus.plexus:plexus-utils:jar:3.0.24:compile
| | \- org.apache.commons:commons-lang3:jar:3.5:compile
| +- org.apache.maven:maven-artifact:jar:3.5.0:compile
| \- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.3:compile
| +- javax.enterprise:cdi-api:jar:1.0:compile
| | +- javax.annotation:jsr250-api:jar:1.0:compile
| | \- javax.inject:javax.inject:jar:1:compile
| +- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.3:compile
| +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
| \- org.codehaus.plexus:plexus-classworlds:jar:2.5.2:compile
+- org.eclipse.jetty.aggregate:jetty-all-server:jar:8.2.0.v20160908:compile
| +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile
| +- org.eclipse.jetty.orbit:javax.security.auth.message:jar:1.0.0.v201108011116:compile
| +- org.eclipse.jetty.orbit:javax.mail.glassfish:jar:1.4.1.v201005082020:compile
| +- org.eclipse.jetty.orbit:javax.activation:jar:1.1.0.v201105071233:compile
| \- org.eclipse.jetty.orbit:javax.annotation:jar:1.1.0.v201108011116:compile
+- org.scala-lang:scala-library:jar:2.11.8:compile
+- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.5:provided
+- org.scalatest:scalatest_2.11:jar:3.0.3:test
| +- org.scalactic:scalactic_2.11:jar:3.0.3:test
| +- org.scala-lang:scala-reflect:jar:2.11.8:compile
| +- org.scala-lang.modules:scala-xml_2.11:jar:1.0.5:compile
| \- org.scala-lang.modules:scala-parser-combinators_2.11:jar:1.0.4:compile
\- org.specs2:specs2-core_2.11:jar:2.5:test
\- org.specs2:specs2-matcher_2.11:jar:2.5:test
\- org.specs2:specs2-common_2.11:jar:2.5:test
+- org.scalaz:scalaz-core_2.11:jar:7.2.0:test
\- org.scalaz:scalaz-concurrent_2.11:jar:7.2.0:test
\- org.scalaz:scalaz-effect_2.11:jar:7.2.0:test
我已经尝试了 3 天来解决这个问题。
补充一下...这是 JDK1.8 和 Maven 3.3.9。
求助!?!
编辑::
如果我在我的 mojo class 头部显式实例化一个记录器,我会得到以下堆栈跟踪:
com.google.inject.ProvisionException:无法配置,看到以下错误:
1) Error injecting constructor, java.lang.ClassCastException: org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext at com.cerner.clinicaldev.gatlingplugin.GatlingPlugin.(Unknown Source) while locating com.cerner.clinicaldev.gatlingplugin.GatlingPlugin
1 error at com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1025) at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051) at org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClass.java:48) at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81) at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:53) at com.google.inject.internal.ProviderInternalFactory.call(ProviderInternalFactory.java:65) at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:115) at org.eclipse.sisu.bean.BeanScheduler$Activator.onProvision(BeanScheduler.java:176) at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:126) at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:68) at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:63) at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:45) at com.google.inject.internal.InjectorImpl.call(InjectorImpl.java:1016) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) at com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1012) at org.eclipse.sisu.inject.Guice4.get(Guice4.java:162) at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:81) at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51) at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:263) at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:255) at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:517) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:121) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:199) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: java.lang.ClassCastException: org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext at com.cerner.clinicaldev.gatlingplugin.GatlingPlugin.(GatlingPlugin.scala:20) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.google.inject.internal.DefaultConstructionProxyFactory.newInstance(DefaultConstructionProxyFactory.java:86) at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105) at com.google.inject.internal.ConstructorInjector.access[=14=]0(ConstructorInjector.java:32) at com.google.inject.internal.ConstructorInjector.call(ConstructorInjector.java:89) at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:115) at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:133) at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:68) at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:87) at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267) at com.google.inject.internal.InjectorImpl.call(InjectorImpl.java:1016) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) at com.google.inject.internal.InjectorImpl.get(InjectorImpl.java:1012)
尝试添加以下依赖项,其中包括 logback-classic
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
它包含在
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
将你的记录器初始化为你 class :-
private static final Logger logger = LoggerFactory.getLogger(DemoClass.class)
最后,我将maven-plugin和gatling项目分离出来,并从其他依赖中排除了slfj。
我在 Play Framework 中遇到了类似的问题:
我唯一要做的就是将 Provided
添加到依赖项中。
这是我的案例 SBT:
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.26" % Provided,
我的标准错误有:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/wf/.m2/repository/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/wf/.m2/repository/ch/qos/logback/logback-classic/1.1.5/logback-classic-1.1.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
指向 http://www.slf4j.org/codes.html#multiple_bindings,它建议将排除项添加到不需要的绑定中。所以我做了一个
mvn dependency:tree | grep -B1 -C1 logback
显示例如
[INFO] +- nl.vaneijndhoven.dukes:rc-watchdog:jar:0.0.2:compile
[INFO] \- ch.qos.logback:logback-classic:jar:1.1.5:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.1.5:compile
[INFO] \- org.slf4j:slf4j-api:jar:1.7.16:compile
虽然有更新版本的 logback-classic:
https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.2.3
在我的 eclipse 工作区的 pomfiles 中的版本号 1.7.25 和 1.7.21 之后,我发现我直接使用 vert.x 作为依赖项目(用于调试目的)。当我从构建路径中删除该项目时,我很好。
所以一般的方法是查看你的依赖关系
mvn dependency:tree
并将 slf4j 从冲突的依赖项中排除或将它们一起删除。