SpringデータのSpring asm依存性の問題
Springデータを使用するMongoDB 1.2.1.RELEASEとSpring core 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データリリースを待つ:)