使用Spring Data MongoDB 1.2.1.RELEASE和Spring核心3.2.2.RELEASE,在系统启动时,它会遇到一些奇怪的spring-asm IncompatibleClassChangeError
错误:
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>
解
这是因为Spring数据正在获取旧的spring-asm 3.1.4.RELEASE,并且与最新的Spring核心3.2.2.RELEASE冲突。
使用Maven的命令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
修复它的几种方法。
1.定义Spring数据依赖关系“ AFTER ”。 Maven传递依赖项将自动获取正确的Spring依赖项。
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>
再次检查Maven依赖树。
2.将spring-asm
添加到排除列表。
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.等待最新的Spring数据发布🙂
注意
请参阅此线程 ,以进行进一步的讨论。
标签: 弹簧数据
翻译自: https://mkyong.com/mongodb/spring-asm-dependency-issue-in-spring-data/