John
John

Reputation: 5287

java.lang.IllegalAccessError while starting Spring application on Tomcat 8

I am getting this very strange error when i try to run the project on Tomcat 8:

INFO o.s.web.context.ContextLoader - Root WebApplicationContext: initialization started . INFO o.s.w.c.s.AnnotationConfigWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Jun 29 10:59:34 CEST 2015]; root of context hierarchy . INFO o.s.w.c.s.AnnotationConfigWebApplicationContext - Registering annotated classes: [class com...]

ERROR o.s.web.context.ContextLoader - Context initialization failed java.lang.IllegalAccessError: tried to access method org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingletonMutex()Ljava/lang/Object; from class org.springframework.context.event.AbstractApplicationEventMulticaster

Full stack trace bellow:

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_45\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\glassfish4\jdk7\jre\bin;C:\Program Files\TortoiseSVN\bin;D:\apache-maven-3.2.3\bin;C:\Program Files (x86)\QuickTime\QTSystem\;. lip 29, 2015 11:40:01 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-nio-8088"] lip 29, 2015 11:40:01 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector INFO: Using a shared selector for servlet write/read lip 29, 2015 11:40:01 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-nio-8099"] lip 29, 2015 11:40:01 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector INFO: Using a shared selector for servlet write/read lip 29, 2015 11:40:01 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 823 ms lip 29, 2015 11:40:01 AM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina lip 29, 2015 11:40:01 AM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/8.0.23 lip 29, 2015 11:40:04 AM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. lip 29, 2015 11:40:04 AM org.apache.catalina.core.ApplicationContext log INFO: Spring WebApplicationInitializers detected on classpath: [com.siemens.ott.RestServiceWebAppIntializer@5fb6fe5e] lip 29, 2015 11:40:04 AM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext .11:40:04.745 INFO o.s.web.context.ContextLoader - Root WebApplicationContext: initialization started .11:40:04.760 INFO o.s.w.c.s.AnnotationConfigWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Jun 29 11:40:04 CEST 2015]; root of context hierarchy .11:40:04.848 INFO o.s.w.c.s.AnnotationConfigWebApplicationContext - Registering annotated classes: [class com.ott.BusinessBeans] .11:40:05.192 ERROR o.s.web.context.ContextLoader - Context initialization failed java.lang.IllegalAccessError: tried to access method org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingletonMutex()Ljava/lang/Object; from class org.springframework.context.event.AbstractApplicationEventMulticaster at org.springframework.context.event.AbstractApplicationEventMulticaster.setBeanFactory(AbstractApplicationEventMulticaster.java:84) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.(SimpleApplicationEventMulticaster.java:60) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster(AbstractApplicationContext.java:667) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:471) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.9.RELEASE.jar:4.0.9.RELEASE] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727) [catalina.jar:8.0.23] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) [catalina.jar:8.0.23] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.23] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [catalina.jar:8.0.23] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399) [catalina.jar:8.0.23] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_45] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45] lip 29, 2015 11:40:05 AM org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.IllegalAccessError: tried to access method org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingletonMutex()Ljava/lang/Object; from class org.springframework.context.event.AbstractApplicationEventMulticaster at org.springframework.context.event.AbstractApplicationEventMulticaster.setBeanFactory(AbstractApplicationEventMulticaster.java:84) at org.springframework.context.event.SimpleApplicationEventMulticaster.(SimpleApplicationEventMulticaster.java:60) at org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster(AbstractApplicationContext.java:667) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:471) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 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)

My first thought was that there are some errors in Spring version but i cannot find anything. This is pretty much same project setup i have used couple of times, with the only difference that this is java 8 project.

Project is Dynamic Web Module 3.1.

Bellow are dependencies from the .pom file, i don't see any collisions in the versions.

Kindly help if somebody encountered this before.

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>2.2.1.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-test</artifactId>
        <version>2.2.1.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
        <version>1.6.3</version>
    </dependency>

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.1.1.Final</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5</version>
    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>javax.xml</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.1</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.12</version>
    </dependency>
</dependencies>

mvn dependecy tree:

C:\Users\Z003DP9F\java-8 workspace\workspace\vmgw>mvn dependency:tree [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building vmgw 1.0 [INFO] ------------------------------------------------------------------------ [WARNING] The artifact javax.xml:jaxb-api:jar:2.1 has been relocated to javax.xml.bind:jaxb-api:jar:2.1 [INFO] [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ vmgw --- [WARNING] The artifact javax.xml:jaxb-api:jar:2.1 has been relocated to javax.xml.bind:jaxb-api:jar:2.1 [INFO] com.siemens.ott:vmgw:war:1.0 [INFO] +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile [INFO] | - commons-logging:commons-logging:jar:1.2:compile [INFO] +- org.springframework.ws:spring-ws-test:jar:2.2.1.RELEASE:compile [INFO] | +- org.springframework.ws:spring-xml:jar:2.2.1.RELEASE:compile [INFO] | - xmlunit:xmlunit:jar:1.5:compile [INFO] +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile [INFO] | +- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile [INFO] | | - aopalliance:aopalliance:jar:1.0:compile [INFO] | +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile [INFO] | - org.springframework:spring-expression:jar:4.1.6.RELEASE:compile [INFO] +- org.springframework:spring-webmvc:jar:4.1.6.RELEASE:compile [INFO] | - org.springframework:spring-web:jar:4.1.6.RELEASE:compile [INFO] +- ch.qos.logback:logback-classic:jar:1.1.3:compile [INFO] | +- ch.qos.logback:logback-core:jar:1.1.3:compile [INFO] | - org.slf4j:slf4j-api:jar:1.7.7:compile [INFO] +- wsdl4j:wsdl4j:jar:1.6.3:compile [INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:provided [INFO] +- javax.annotation:javax.annotation-api:jar:1.2:compile [INFO] +- javax.xml.bind:jaxb-api:jar:2.1:compile [INFO] | +- javax.xml.stream:stax-api:jar:1.0-2:compile [INFO] | - javax.activation:activation:jar:1.1:compile [INFO] +- org.springframework.ws:spring-ws-core:jar:2.2.1.RELEASE:compile [INFO] | - org.springframework:spring-oxm:jar:4.0.9.RELEASE:compile [INFO] +- junit:junit:jar:4.12:test [INFO] | - org.hamcrest:hamcrest-core:jar:1.3:test [INFO] +- org.springframework:spring-test:jar:4.1.6.RELEASE:compile [INFO] +- commons-io:commons-io:jar:2.4:compile [INFO] +- org.apache.httpcomponents:httpclient:jar:4.5:compile [INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile [INFO] | - commons-codec:commons-codec:jar:1.9:compile [INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile [INFO] +- javax.validation:validation-api:jar:1.1.0.Final:compile [INFO] - org.hibernate:hibernate-validator:jar:5.1.1.Final:compile [INFO] +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile [INFO] - com.fasterxml:classmate:jar:1.0.0:compile [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS

Upvotes: 3

Views: 8549

Answers (1)

M. Deinum
M. Deinum

Reputation: 124441

The problem is you are mixing different versions of Spring which are incompatible. Regardless you should never mix jars from different versions of any framework (Spring, Hibernate, JSF etc.) as that is trouble bound to happen.

The best way is to simply use the Spring IO Platform.

Add the following to your pom

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.spring.platform</groupId>
            <artifactId>platform-bom</artifactId>
            <version>1.1.2.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Then remove the versions in your pom as the versions are now being managed by the platform-bom, you should now have versions that work together and no more conflicting versions. For a list of managed version check this appendix.

Upvotes: 7

Related Questions