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.

上一篇: New Relic for PHP, with cPanel + VPS
下一篇: How to read and parse CSV file in Java
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 

一号门极客CMS,由Python,Django,MySQL,Apache,Mod Wsgi 强力驱动.
鄂ICP备14001754号-3