SLF4J: java.lang.IllegalStateException: org.slf4j.LoggerFactory could not be successfully initialized - maven

I have the following maven dependency in my pom file:
<!-- depends on slf4j-api, log4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
When I deploy the project into tomcat, I am getting the error message:
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.ExceptionInInitializerError
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:80)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4819)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5466)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalStateException: org.slf4j.LoggerFactory could not be successfully initialized. See also http://www.slf4j.org/codes.html#unsuccessfulInit
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:288)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at org.springframework.web.context.ContextCleanupListener.<clinit>(ContextCleanupListener.java:43)
... 16 more
When I look at the deployed war file, I see in the war file the following jars (among others):
slf4j-api-1.6.4.jar
slf4j-log4j12-1.6.4.jar
The strange thing is, that I don't see there any log4j.jar (even though it's a dependency of slf4j-log4j12-1.6.4.jar
Questions:
Why was log4j.jar not packed in the war file?
What does the error message mean and how to solve it?

I had this issue due to a bad jar file in the repository. Deleting the entire log4j directory in the Maven repository fixed it once I did Maven > Update Dependencies and it re-downloaded them.

The simple thing is, cause you didn't give it as dependency in your pom, cause slf4j is a logging facade which means you have to give the real implementation with it. The error message gives you a hint to the explanation of the cause of this error.

I got this error too and I actually had the log4j.jar in my war file.
But it turned out to be a classloader issue in my case: I had a jar in my shared/lib which tried to log with slf4j but that classloader did not have the log4j available.

It seems as if you need to downgrade your project to slf4j 1.4.2 to work with the log4j available in your tomcat. They are binary incompatible. You would also hang on to the provided afterwards, so you dont include them double.
The alternative is to get the other project to include the libraries themselves and remove from tomcat common. I know of no other exclusion mechanism on the tomcat.
For reference, and probably not helpful, I currently deploy on weblogic and it has a deployment specification that allows one to exclude server common classes and use bundled classes instead, such as the below snippet (with reference)

Related

Issue in Jboss 7.2.2 migration

I am deploying a WAR file to JBoss EAP 7.2.2. During deployment, I am getting
"Caused by: java.lang.IllegalArgumentException: Unable to load generated mapper class com.amadeus.jcp.services.ttr.display.structured.builder.response.selma.mapper.offer.DisplayTripCartResponseOfferQuotationMapperSelmaGeneratedClass"
which is caused by "Caused by: java.lang.ClassNotFoundException: com.amadeus.jcp.services.ttr.display.structured.builder.response.selma.mapper.offer.DisplayTripCartResponseOfferQuotationMapperSelmaGeneratedClass"
It is a selma generated class and available in a jar inside WEB-INF/lib.
Same WAR file is deploying successfully in JBoss EAP 7.1.
As per class loader hierarchy, it should be identified but not happening.
Anybody have any idea of this issue, please help.
Verified standalone.xml and jboss-deployment-structure.xml. Using same version before and after migration except for name space version upgrade to subsystems.
Using Java 1.8.0_191

org.hibernate.integrator.spi.Integrator: Provider org.hibernate.envers.boot.internal.EnversIntegrator not a subtype

I am migrating my java web application from Jboss 7.1.1 Final to Wildfly 10,using :
spring 4.2.0,
hibernate 5.0.7,
jpa 2.1
and Mysql database.
I getting the following error while trying to run my code.
2016-07-20 19:30:50,176 ERROR [org.jboss.msc.service.fail]
(ServerService Thread Pool -- 61) MSC000001: Failed to start service
jboss.persistenceunit."ccp-ear-1.0-SNAPSHOT.ear/ccp-entities-1.0-SNAPSHOT.jar#ccpPU":
org.jboss.msc.service.StartException in service
jboss.persistenceunit."ccp-ear-1.0-SNAPSHOT.ear/ccp-entities-1.0-SNAPSHOT.jar#ccpPU":
java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider
org.hibernate.envers.boot.internal.EnversIntegrator not a subtype
at
org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
at
org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
at
org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
at
org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745) at
org.jboss.threads.JBossThread.run(JBossThread.java:320) Caused by:
java.util.ServiceConfigurationError:
org.hibernate.integrator.spi.Integrator: Provider
org.hibernate.envers.boot.internal.EnversIntegrator not a subtype at
java.util.ServiceLoader.fail(ServiceLoader.java:239) at
java.util.ServiceLoader.access$300(ServiceLoader.java:185) at
java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480) at
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:324)
at
org.hibernate.integrator.internal.IntegratorServiceImpl.(IntegratorServiceImpl.java:40)
at
org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:213)
at
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildBootstrapServiceRegistry(EntityManagerFactoryBuilderImpl.java:365)
at
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.(EntityManagerFactoryBuilderImpl.java:166)
at
org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
at
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
at
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:160)
at
org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:135)
at
org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:318)
at
org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$1100(PersistenceUnitServiceImpl.java:67)
at
org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167)
... 7 more
You need to delete the hibernate.cfg.xml and move the configuration from this file to persistence.xml.
Then You have also to remove all hibernate files from WEB-INF/lib folder, because WildFly has its own ones and this situation also possibly made a conflict.
More details on this problem in this link : JBoss Community Forum
I also had a similar issue with Wildfly 10.0.0.Final. In my project also we have all hibernate related libraries within the project's lib directory. But the jboss provided libraries caused conflicts so i have removed the content within the tag <module xmlns="urn:jboss:module:1.3" name="org.hibernate"> in module.xml file available in JBOSS_HOME\modules\system\layers\base\org\hibernate\main directory. Also i have removed the dependencies of hibernate libraries in jboss-deployment-struture.xml as,
<exclusions>
<module name="org.hibernate" slot="main"/>
</exclusions>
After these changes i can able overcome the conflict issues related to hibernate.Hope this will help.
Please note jboss-deployment-struture.xml change alone has not resolved my issue the change mentioned on module.xml file is mandatory.

java.lang.NoClassDefFoundError: org/springframework/web/context/ContextCleanupListener issue

I get this error
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/web/context/ContextCleanupListener
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:80)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5035)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5687)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1028)
at org.apache.catalina.startup.HostConfig.undeploy(HostConfig.java:1498)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1425)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1646)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:328)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1546)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1524)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.ContextCleanupListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 16 more
I look in my deployed folder however and I see the jar that contains that file, what am I doing wrong?
https://github.com/davidahines/spacechip/tree/spring_security
The issue is that when I try to go to localhost:8080/spacechip I get "The resource is unavailable."
There is my configuration.
try change dependency of spring-web to 3.0.5.RELEASE in your pom, you are currently have 2 version on classpath
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
The jar may be in your deployed folder, but is the jar (or your deployed folder with a wildcard) in the CLASSPATH?
EnvironmentAware is located in the spring-context-3.1.1.RELEASE.jar, so you are missing that one.
Also recheck your Maven POM file so that you are not missing any other Spring library, like spring-web, spring-webmvc (you may have these since the DispatcherServlet class if found), spring-orm if you use an ORM like Hibernate, spring-jms if you use JMS, etc.

Spring 3.1 not able to load Configuration Class:

I am working on project that has Rest Service with Spring 3.1.0. Release.
I am using Config class to load beans.
As suggested, using cglib 2.2 and asm-3.3 jars.
This fails in websphere 8.5 with following exception. But works in Apache Tomcat 7.0.
[12/19/12 12:47:26:439 EST] 00000062 webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[dispatcher]: java.lang.IllegalStateException: Cannot load configuration class: com.hps.config.ApplicationConfig
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:313)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:197)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:620)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1651)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:414)
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:746)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:634)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:426)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:718)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1170)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1370)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:638)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:769)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1364)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2169)
Caused by: java.lang.VerifyError: JVMVRFY007 final method overridden; class=net/sf/cglib/core/DebuggingClassWriter, method=visit(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:262)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69)
at com.ibm.ws.classloader.CompoundClassLoader._defineClass(CompoundClassLoader.java:852)
at com.ibm.ws.classloader.CompoundClassLoader.localFindClass(CompoundClassLoader.java:762)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:585)
at java.lang.ClassLoader.loadClass(ClassLoader.java:627)
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:85)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:162)
at net.sf.cglib.core.AbstractClassGenerator.<init>(AbstractClassGenerator.java:38)
at net.sf.cglib.core.KeyFactory$Generator.<init>(KeyFactory.java:127)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:112)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:136)
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:303)
... 109 more
Any suggestion on how to fix this issue.
Tried with different versions of cglib and asm jars, but no luck..
Make sure all the dependent JAR files are stored in WEB-INF/lib directory of your WAR file including Sam-3.3. If your using Maven then make sure you don't exclude this JAR or inadvertently set its scope as provided.
Now you you deploy the application in WebSphere make sure you set the application class loading before to application first (parent last). To do this in WebSphere you need to find the link Manage Modules and locate class loading link, don't really remember what it was in WebSphere however should be easy to find. This should resolve your issues.
Update: just noticed the link you provided already suggests using parent last. In WebSphere I find this is a must otherwise you will hit many of these issues and furthermore upgrades become much easier!
I am able to resolve this issue..
Issue is with Websphere 8.5
It has own version of asm4.0 jars. And spring3.1 uses cglib2.2 jar that is only compatible with asm3.3. asm4.0 jar of websphere is the culprit..
workaround is to use cglib-nodep jar instead of cglib2.2 jar
http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14880673
It seems that this was a bug (PM71336) in Websphere 8.5
The bug has been fixed in the Websphere V8.5 Fix Pack 2
http://www-01.ibm.com/support/docview.wss?uid=swg24034672
Use cglib-nodep jar instead of cglib2.2 jar. Also, don't forget to remove asm3.3 jar from your lib. Initially I wasn't removing asm3.3 jar which was still causing the problem.

browser-mob proxy - java.lang.SecurityException when executing jar packaged by maven

I am using browser-mob proxy in my web application to emulate a proxy server. After performing an mvn clean package, when I execute the jar I get the following the error:
Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry org/bouncycastle/asn1/ocsp/ResponderID.class
at sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:399)
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:250)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:193)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:305)
at java.util.jar.JarVerifier.update(JarVerifier.java:216)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:341)
at java.util.jar.JarFile.getInputStream(JarFile.java:406)
at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:752)
at sun.misc.Resource.cachedInputStream(Resource.java:77)
at sun.misc.Resource.getByteBuffer(Resource.java:160)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:436)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:472)
The Meta-Inf folder does not have any signature certificates which I can exclude while building my jar.
I remember having a similar problem with some bouncycastle classes.
My problem was caused by a "ueber-jar" (in my case apache-ds-all) that contained not only the classes from the apache-ds project, but also all classes from the apache-ds 3rd Party dependencies.
Since the bouncycastle classes are originally shipped in a signed jar file, I got a security Exception when the classes where loaded from a different location - which is the whole point of signing a JAR in the first place.
I'd recommend to scan all the JAR files in your classpath to see if org/bouncycastle/asn1/ocsp/ResponderID.class is contained in a non-bouncycastle distribution jar file.
Hope that helps !
I had the security problem in the ic4u package. I just excluded it form the dependency and everything worked fine.
<dependency>
<groupId>biz.neustar</groupId>
<artifactId>browsermob-proxy</artifactId>
<version>${browser-mob-version}</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
</exclusion>
<exclusion>
<artifactId>icu4j</artifactId>
<groupId>com.ibm.icu</groupId>
</exclusion>
</exclusions>
</dependency>
I had exactly the same problem with iText 4.2.0 and the bouncycastle library (SecurityExceptions related to ResponderID and other classes).
I ended up deleting the META-INF directories in the signed jars shipped with iText. It might not be the most elegant way but at least it solved the problem for me.

Resources