Spring Asm Dependency Issue: java.lang.IncompatibleClassChangeError - Fixed
If you have migrated / upgraded your project to Spring Framework 3.2 and project builds successfully but when application starts, you are getting IncompatibleClassChangeError, then this post will help you to resolve the same.
Tools and Technologies used in this article :
Error Stack-traceServer Console
In Spring Framework 3.2, spring-asm is upgraded to org.objectweb.asm 4.0 and included in spring-core. Now there is no need to add this spring-asm3 dependency separately within the build script. If it is declared, then remove the same while migrating to 3.2.
There are chances that your project is using other spring extension (say Spring Security 3.1.4), which is dependent on spring-asm3. As a result different versions of asm module may be available in the classpath.
When application starts, different versions of classes may get loaded - ClassMetadataReadingVisitor from spring-core (containing asm 4.0) and ClassVisitor from spring-asm (containing asm 3.x). As a result ClassMetadataReadingVisitor violates the contract of interface ClassVisitor and resulting the IncompatibleClassChangeError.
To avoid this, you need to add spring-asm to the exclusion list as shown below.
Check for spring-asm Dependency
Go to the project directory in the command prompt and execute mvn dependency:treeCommand Prompt
From the above dependency check, we can see that old spring-asm (org.springframework:spring-asm:jar:3.0.7.RELEASE) will also be loaded along with the new asm included in spring-core (org.springframework:spring-core:jar:3.2.3.RELEASE.
Exclude spring-asm Dependency
Now add spring-asm in the exclusion list of each dependent dependency (for example spring-security-core).pom.xml
Run the maven dependency command again to verify.Command Prompt
Hopefully, this will resolve your IncompatibleClassChangeError issue, just like mine.