ClassCaseException org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
Asked Answered
C

4

6

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

I am writing a maven mojo that spins up a Jetty implementation and runs Gatling programmatically. I have tried excluding slf4j from the io.gatling:gatling-app:2.2.5 and including in the maven-enforcer-plugin as a banned dependency all no no avail.

I cannot see anywhere else in the dependency tree that includes it;

+- 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

I have been trying for 3 days to resolve this.

Just to add...this is JDK1.8 and Maven 3.3.9.

Help!?!

EDIT::

If I explicitly instantiate a logger at the head of my mojo class I get the following stack trace:

com.google.inject.ProvisionException: Unable to provision, see the following errors:

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$2.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$1.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$2$1.call(InjectorImpl.java:1016) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012) at org.eclipse.sisu.inject.Guice4$1.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$1.newInstance(DefaultConstructionProxyFactory.java:86) at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105) at com.google.inject.internal.ConstructorInjector.access$000(ConstructorInjector.java:32) at com.google.inject.internal.ConstructorInjector$1.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$2$1.call(InjectorImpl.java:1016) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)

Counterespionage answered 16/7, 2017 at 21:38 Comment(0)
C
0

In the end, I separated out the the maven-plugin and gatling projects and excluded slfj from other dependencies.

Counterespionage answered 6/10, 2017 at 13:26 Comment(0)
E
1

I had a similar problem within the Play Framework:

The only thing I had to do was to add the Provided to the dependency.

Here my case with SBT:

libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.26" % Provided,
Evanescent answered 20/12, 2019 at 10:22 Comment(0)
H
0

Trying add bellow dependency which included logback-classic

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.7</version>
</dependency>

it is included in

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.1.3</version>
</dependency>

initialize your logger into you class :-

private static final Logger logger = LoggerFactory.getLogger(DemoClass.class)
Hortensiahorter answered 17/7, 2017 at 5:58 Comment(3)
you can try this code for cast LoggerContext context = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory(); and you can refer this link : programcreek.com/java-api-examples/…Hortensiahorter
Just getting class cast exceptions. :(Counterespionage
Appreciate your help, I think the problem is the maven-plugin-api uses slf4j and so does Gatling and they are competing. I need to find a way of telling maven to use the same as Gatling.Counterespionage
C
0

In the end, I separated out the the maven-plugin and gatling projects and excluded slfj from other dependencies.

Counterespionage answered 6/10, 2017 at 13:26 Comment(0)
C
0

My stderr has:

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]

which points to http://www.slf4j.org/codes.html#multiple_bindings which recommends to add exclusions to the non-wanted bindings. So I did a

mvn dependency:tree | grep -B1 -C1 logback

which showed e.g

[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

while there is a newer version of logback-classic:

https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.2.3

Following the version numbers 1.7.25 and 1.7.21 in the pomfiles in my eclipse workspace i found out that I was using vert.x directly as a dependent project (for debugging purposes). When i removed that project from the build path i was fine.

So the general approach is looking at your dependencies with

mvn dependency:tree

and exclude slf4j from conflicting dependencies or remove them all together.

Clova answered 10/3, 2020 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.