Main Tutorials

Spring asm dependency issue in Spring Data

Using Spring Data MongoDB 1.2.1.RELEASE and Spring core 3.2.2.RELEASE, while system is starting, it hits some weird spring-asm IncompatibleClassChangeError errors :


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

	<properties>
		
		<spring.version>3.2.2.RELEASE</spring.version>
		<springdata.version>1.2.1.RELEASE</springdata.version>
	
	</properties>

	<dependencies>

		<!-- Spring Core -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<!-- Spring Data for MongoDB -->
		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>${springdata.version}</version>
		</dependency>

		<!-- Spring Web-->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>

	</dependencies>

Solution

This is because the Spring-data is getting the old spring-asm 3.1.4.RELEASE, and conflicts with the latest Spring core 3.2.2.RELEASE.

Check all dependencies with Maven’s command mvn dependency:tree.


# mvn dependency:tree

[INFO] +- org.springframework:spring-core:jar:3.2.2.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile

[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.2.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:3.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.1.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-asm:jar:3.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:3.1.4.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.5.1.RELEASE:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.1:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.1:runtime

[INFO] +- org.springframework:spring-web:jar:3.2.2.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- org.springframework:spring-aop:jar:3.2.2.RELEASE:compile
[INFO] \- org.springframework:spring-webmvc:jar:3.2.2.RELEASE:compile

Few ways to fix it.

1. Define the Spring data dependency “AFTER” the Spring related dependencies. Maven transitive dependencies will fetch the correct Spring dependencies automatically.

pom.xml

	<properties>
		
		<spring.version>3.2.2.RELEASE</spring.version>
		<springdata.version>1.2.1.RELEASE</springdata.version>
	
	</properties>

	<dependencies>

		<!-- Spring Core -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<!-- Spring Web-->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>

                <!-- Spring Data for MongoDB , define at last-->
		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>${springdata.version}</version>
		</dependency>

	</dependencies>

Check Maven dependency tree again.

2. Add spring-asm to exclusion list.

pom.xml
	
        <!-- Spring Data for MongoDB , define at last-->
	<dependency>
	    <groupId>org.springframework.data</groupId>
	    <artifactId>spring-data-mongodb</artifactId>
	    <version>${springdata.version}</version>
                <exclusions>
		   <exclusion>
		      <groupId>org.springframework</groupId>
                      <artifactId>spring-asm</artifactId>
		  </exclusion>
		</exclusions>
	</dependency>

3. Wait latest Spring data release 🙂

Note
Refer this thread, for further discussion.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
6 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
naveen kumar
9 years ago

brilliant

Ajesh
5 years ago

What a MAN you are :):):):

zanyme
9 years ago

Thanks !! It’s very helpful. in my case, com.googlecode.ehcache-spring-annotations has references spring-asm. I doing same action like you had been, I solved it. thanks again.

krishna kumar
10 years ago

You the Best of all. i have searched in many sites. but after seeing your solution the error is 100% gone. The second option solution worked for me. Thank you .Thanks A lot!!!!!!!!!!

Peter Perhac
10 years ago

you, man, are THE man! thank so much for this. i’ve tried just about everything, but reordering the dependencies in the pom finally worked.

vadim
10 years ago

Thanks, your second solution worked for me…. Actualy, I haven’t check the first one, neither the third ))