20

I am developing a Java web project using the latest Spring framework version (3.2.2-RELEASE), but now I have a problem when the project is started up. The detail error is

java.lang.IncompatibleClassChangeError:
class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class.

I have researched this problem on Internet and this site also, and got some clues. I have removed the asm and spring-asm libraries out of my project, but it did not work. I see that there are another ClassVisitor interface which is defined in rt.jar of default JRE. Is this the reason cause this conflict?

But I do recognized that:

class ClassMetadataReadingVisitor extends ClassVisitor implements ClassMetadata {

    private String className;
        ....
}

ClassMetadataReadingVisitor refers to class org.springframework.asm.ClassVisitor (already available in spring-core package), so how can it conflict with the interface com.sun.xml.internal.ws.org.objectweb.asm.ClassVisitor of JRE? I don't know how can this happen?

Here is full stack-strace:

[ERROR 13:49:39] (ContextLoader:319) - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\workspace\.projects\myproject\trunk\target\myproject\WEB-INF\classes\com\myproject\action\AuthenticationAction.class]; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:63)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:257)
    ... 47 more
[ERROR 13:49:39] (ContextLoader:319) - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\workspace\.projects\myproject\trunk\target\myproject\WEB-INF\classes\com\myproject\action\AuthenticationAction.class]; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:63)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:257)
    ... 47 more

And here is list of dependencies:

activation-1.0.2.jar  
antlr-2.7.7.jar  
antlr-runtime-3.3.jar  
arena-0.1.jar  
asm-3.3.1.jar (removed from classpath)  
aspectjweaver.jar  
bcprov-jdk16-145.jar  
c3p0-0.9.1.2.jar  
cglib-2.1_3.jar  
com.springsource.org.apache.xml.serializer-2.7.1.jar  
commons-beanutils-1.8.3.jar  
commons-codec-1.7.jar  
commons-collections-3.2.1.jar  
commons-dbcp-1.4.jar  
commons-digester-2.1.jar  
commons-fileupload-1.2.2.jar  
commons-httpclient-3.1.jar  
commons-io-2.4.jar  
commons-lang-2.6.jar  
commons-logging-1.1.1.jar  
commons-pool-1.6.jar  
commons-vfs-patched-1.9.1.jar  
commons-vfs2-2.0.jar  
csv.jar  
dom4j-1.6.1.jar  
fop-1.0.jar  
gson-2.2.2.jar  
htmlcleaner-2.4.jar  
httpclient-4.2.3.jar  
httpcore-4.2.3.jar  
httpcore-nio-4.2.3.jar  
httpmime-4.2.3.jar  
jaxen-1.1-beta-6.jar  
jcifs-1.3.15.jar  
jdom-1.0.jar  
jersey-client-1.8.jar  
jersey-core-1.8.jar  
jersey-multipart-1.0.3.144640.jar  
jersey-server-1.8.jar  
jersey-spring-1.8.jar  
joda-time-2.2.jar  
joda-time-jsptags-1.1.1.jar  
jodconverter-2.2.2.jar  
json-lib-2.4-jdk15.jar  
json-simple-1.1.1.jar  
json-taglib-0.4.1.jar  
jsoup-1.7.2.jar  
jstl-1.2.jar  
juh-3.2.1.jar  
jurt-3.2.1.jar  
log4j-1.2.17.jar  
mail-1.4.5.jar  
persistence-api-1.0.2.jar  
poi-3.9.jar  
poi-ooxml-3.9.jar  
poi-ooxml-schemas-3.9.jar  
poi-scratchpad-3.9.jar  
postgresql-9.1-901-1.jdbc4.jar  
quartz-2.1.6.jar  
ridl-3.2.1.jar  
scribe-1.3.3.jar  
slf4j-api-1.7.5.jar  
slf4j-jdk14-1.7.5.jar  
spring-aop-3.2.2.RELEASE.jar  
spring-asm-3.1.4.RELEASE.jar (removed from classpath)  
spring-beans-3.2.2.RELEASE.jar  
spring-context-3.2.2.RELEASE.jar  
spring-context-support-3.2.2.RELEASE.jar  
spring-core-3.2.2.RELEASE.jar  
spring-expression-3.2.2.RELEASE.jar  
spring-jdbc-3.2.2.RELEASE.jar  
spring-tx-3.2.2.RELEASE.jar  
spring-web-3.2.2.RELEASE.jar  
spring-webmvc-3.2.2.RELEASE.jar  
standard-1.1.2.jar  
stax-api-1.0.1.jar  
stringtemplate-4.0.2.jar  
unoil-3.2.1.jar  
velocity-1.7.jar  
velocity-tools-2.0.jar  
wmf2svg-0.9.3.jar  
xalan-2.7.1.jar  
xercesImpl-2.11.0.jar  
xml-apis-1.4.01.jar  
xmlbeans-2.6.0.jar  
xmlgraphics-commons-1.5.jar  
xstream-1.4.4.jar
5
  • Can you please post the list of jars/libraries present in your application and also post complete stack-trace Commented Apr 2, 2013 at 7:12
  • Do you by any change use AOP ? Using tx:annotation driven, or any other form of (Spring) AOP ? See : jira.springsource.org/browse/SEC-2066
    – Daneo
    Commented Apr 4, 2013 at 7:52
  • 1
    I have the same problems in some test cases after migrating to spring 3.2.2. One of them has the exact same message, while another has the following error message : java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
    – Gaetan
    Commented Apr 15, 2013 at 7:52
  • 2
    Looks like a asm version problem. Did you (as I do) upgrade from a pre-3.2 release ? Spring has upgraded asm to 4.0 and moved the code into spring-core.
    – Gaetan
    Commented Apr 15, 2013 at 7:58
  • 1
    Excluding spring-asm from all dependencies that used it has helped in our case.
    – ssasa
    Commented Aug 2, 2013 at 13:48

7 Answers 7

31

I solved my same problem after I generated a mvn dependency:tree and looked for older spring versions in my tree. Indeed, there was a dependency to org.springframework:spring-asm:3.0.7-RELEASE in my dependencies.

2
  • 1
    This is the correct answer, OP is using multiple spring library versions.
    – jelies
    Commented Nov 6, 2013 at 11:04
  • This is the correct answer; agreed. Whenever you see squirrely issues like this, it's almost ALWAYS version conflict Commented May 28, 2014 at 18:09
12

I resolved the same problem by reordering the pom dependencies.

I got issue from org.springframework.security. So I brought it to end of the dependencies.

1
  • 4
    Spring security references previous version of spring. To properly fix this issue you need to run: mvn dependency:tree > dep.txt and then look through what spring artefacts maven resolves. Then exclude all older versions of spring from spring security dependencies.
    – Denis
    Commented Jan 23, 2014 at 16:59
12

If you are using a spring version > 3.2.0, you no longer need to include specifically spring-asm since it has been included in spring-core.

Remove spring-asm from your build definition and ensure that spring-core is there.

See http://docs.spring.io/spring-framework/docs/3.2.16.RELEASE/spring-framework-reference/htmlsingle/#migration-3.2-inline-asm

6

I had similar issue and the root cause was other spring lib include spring-asm 3.1.0 as dependency.

Fixed this issue by exluding the 'spring-asm' from all configuration in my gradle build script.

configurations {
    all*.exclude group: 'org.springframework', module: 'spring-asm'
}
0
6

Same issue for me. I ran 'mvn dependency:tree' and noticed that an older version of spring-aop was being brought in so I added it to the jersey-spring exclusions, which corrected my problem:

    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-spring</artifactId>
        <version>${jersey.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
        </exclusions>
        <scope>provided</scope>
    </dependency>
0
3

I ran into the same problem when trying to add Spring security to the application. The problem was resolved by adding

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.2.2.RELEASE</version>
</dependency>
2

I resolved the problem adding following exclusion in jersey-spring dependency.

<exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
</exclusion>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.