spring (data, mvc, security) 依赖项:IncompatibleClassChangeError
Posted
技术标签:
【中文标题】spring (data, mvc, security) 依赖项:IncompatibleClassChangeError【英文标题】:spring (data, mvc, security) dependencies : IncompatibleClassChangeError 【发布时间】:2013-09-04 15:25:31 【问题描述】:我遇到了无法解决的 spring 依赖项问题。 我使用最新版本的 spring (web mvc ...)、spring security 和 spring data。
当我用maven编译我的项目时,我已经成功构建,但是当我启动tomcat时,我收到以下错误:
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.core.type.clas-s-reading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
这是我的 Maven 依赖项:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.3.RELEASE</spring.version>
<spring.security.version>3.1.4.RELEASE</spring.security.version>
<spring.data.jpa.version>1.3.4.RELEASE</spring.data.jpa.version>
<spring.asm.version>3.1.4.RELEASE</spring.asm.version>
<hibernate-validator.version>4.3.1.Final</hibernate-validator.version>
<hibernate.version>4.2.3.Final</hibernate.version>
<hibernate-jpa-2.0-api.version>1.0.1.Final</hibernate-jpa-2.0-api.version>
<validation.version>1.0.0.GA</validation.version>
<postgresql.version>9.0-801.jdbc4</postgresql.version>
<hsqldb.version>1.8.0.10</hsqldb.version>
<junit.version>4.10</junit.version>
<easymock.version>3.1</easymock.version>
<slf4j.version>1.6.6</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<jackson.version>1.9.12</jackson.version>
<joda.time.version>2.2</joda.time.version>
<guava.version>14.0.1</guava.version>
<antlr.version>2.7.7</antlr.version>
<cglib.nodep.version>3.0</cglib.nodep.version>
</properties>
<dependencies>
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>$spring.version</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>$spring.version</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>$spring.version</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>$spring.version</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- SECURITY -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>$spring.security.version</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>$spring.security.version</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- JPA -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>$hibernate-jpa-2.0-api.version</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>$spring.data.jpa.version</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
<exclusion>
<artifactId>junit-dep</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- JACKSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>$jackson.version</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>$jackson.version</version>
</dependency>
<!-- TESTS -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>$junit.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>$spring.version</version>
<scope>test</scope>
</dependency>
<!-- UTILS -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>$guava.version</version>
</dependency>
<!-- DATES -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>$joda.time.version</version>
</dependency>
<!-- LOGS -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>$log4j.version</version>
</dependency>
</dependencies>
您知道我该如何解决这个问题吗?
提前谢谢你。
编辑: 这是我的 mvn 依赖项:tree
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ schoolme ---
[INFO] com.xtapps.schoolme.server:schoolme:war:0.0.1-SNAPSHOT
[INFO] +- com.xtapps.schoolme.server:business-layer:jar:0.0.1-SNAPSHOT:compile
[INFO] | \- com.xtapps.schoolme.common:datasource-config:jar:0.0.1-SNAPSHOT:compile
[INFO] +- com.xtapps.schoolme.server:data-access-layer:jar:0.0.1-SNAPSHOT:compile
[INFO] +- org.springframework:spring-aop:jar:3.2.4.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-beans:jar:3.2.4.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:3.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:3.2.4.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:3.2.4.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:3.2.4.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:3.2.4.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:3.2.4.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.1.4.RELEASE:compile
[INFO] | \- org.springframework.security:spring-security-core:jar:3.1.4.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.1.4.RELEASE:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] +- org.springframework.data:spring-data-jpa:jar:1.3.4.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:1.5.2.RELEASE:compile
[INFO] | +- org.springframework:spring-orm:jar:3.2.4.RELEASE:compile
[INFO] | +- org.aspectj:aspectjrt:jar:1.7.2:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.1:compile
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.1:runtime
[INFO] +- org.hibernate:hibernate-validator:jar:5.0.1.Final:compile
[INFO] | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.1.GA:compile
[INFO] | \- com.fasterxml:classmate:jar:0.8.0:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.12:compile
[INFO] | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile
[INFO] +- junit:junit:jar:4.10:compile
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] +- org.springframework:spring-test:jar:3.2.4.RELEASE:test
[INFO] +- org.mockito:mockito-all:jar:1.9.0:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- com.google.guava:guava:jar:14.0.1:compile
[INFO] +- joda-time:joda-time:jar:2.2:compile
[INFO] \- log4j:log4j:jar:1.2.17:compile
这是我的父 pom 项目:
<properties>
<spring.version>3.2.4.RELEASE</spring.version>
<spring.security.version>3.1.4.RELEASE</spring.security.version>
<spring.data.jpa.version>1.3.4.RELEASE</spring.data.jpa.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>$spring.version</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>$spring.version</version>
</dependency>
<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>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>$spring.version</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>$spring.security.version</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>$spring.security.version</version>
</dependency>
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>$spring.data.jpa.version</version>
</dependency>
</dependencies>
</dependencyManagement>
这是我的 pom 项目
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate.version>4.2.3.Final</hibernate.version>
<hibernate-jpa-2.0-api.version>1.0.1.Final</hibernate-jpa-2.0-api.version>
<postgresql.version>9.0-801.jdbc4</postgresql.version>
<hsqldb.version>1.8.0.10</hsqldb.version>
<junit.version>4.10</junit.version>
<log4j.version>1.2.17</log4j.version>
<schoolme.version>0.0.1-SNAPSHOT</schoolme.version>
<jackson.version>1.9.12</jackson.version>
<joda.time.version>2.2</joda.time.version>
<guava.version>14.0.1</guava.version>
<jaxb-api.version>2.1</jaxb-api.version>
</properties>
<dependencies>
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- SECURITY -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<!-- JPA - HIBERNATE -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>$hibernate-jpa-2.0-api.version</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
</dependency>
<!-- SERVLET API-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<!-- JACKSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>$jackson.version</version>
</dependency>
<!-- TESTS -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>$junit.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
</dependency>
<!-- UTILS -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>$guava.version</version>
</dependency>
<!-- DATES -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>$joda.time.version</version>
</dependency>
<!-- LOGS -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>$log4j.version</version>
</dependency>
<!--
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
-->
</dependencies>
我总是有同样的错误。 感谢您的回复。
【问题讨论】:
为什么要使用不同版本的spring JARS..? 最小版本的spring是3.2.3.RELEASE,spring security是3.1.4.RELEASE,spring data是1.3.4.RELEASE。我不认为我使用不同版本的弹簧罐...... 你能发布你的 Maven 层次结构.. 吗?你能检查任何不兼容的 JARS 的层次结构吗? 我编辑了我的帖子以添加 maven 依赖树和新的 pom.xml 文件。谢谢 你确实删除了冲突对..?你能运行代码并检查你是否得到同样的错误..? 【参考方案1】:使用<dependencyManagement>
块Documentation 代替所有重复的排除。这会强制使用特定版本的库。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>$spring.version</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>$spring.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>$spring.version</version>
</dependency>
<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>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>$spring.version</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>$spring.security.version</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>$spring.security.version</version>
</dependency>
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>$spring.data.jpa.version</version>
</dependency>
</dependencies>
</dependencyManagement>
在你的依赖树中,你有一个旧版本的 spring-orm,将它包含在你的依赖列表中。 (虽然添加 <dependencyManagement />
块也可以解决这个问题,因为它的版本会自动升级到 3.2.3)。
最后找出哪个依赖项正在拉入 spring-asm.jar 并排除它。 Spring 3.2 及更高版本包含了自己的 ASM 版本,不再需要单独的 jar,它现在包含在 spring-core.jar 中。有关 spring 3.2 中更改/更新的更多信息,请查看the reference guide。
<dependencies>
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- SECURITY -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<!-- JPA -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>$hibernate-jpa-2.0-api.version</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<!-- JACKSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>$jackson.version</version>
</dependency>
<!-- TESTS -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>$junit.version</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<!-- UTILS -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>$guava.version</version>
</dependency>
<!-- DATES -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>$joda.time.version</version>
</dependency>
<!-- LOGS -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>$log4j.version</version>
</dependency>
</dependencies>
关于您的其他依赖项,jpa-api 和 validator-api 通过包含 hibernate 自动包含在内。你还需要hibernate-validator 4.3.1.Final(没有4.2.3.Final)。
【讨论】:
感谢您的回复。但这并不能解决我的问题。我的项目中有一个父 pom。我像你说的那样将spring依赖项放在依赖管理中,而在项目pom中没有版本的依赖项。我总是有同样的错误。当我使用 maven(maven 构建、安装等)构建时,我没有它。当我启动tomcat(在intellij上)时出现这个问题。 我也在使用 javax.servlet-api、javax.inject 和 mockito-all(用于休息测试) 当我在intellij上搜索ClassVisitor类型时,我发现了三个接口。第一个在spring core中,第二个在mockito中(我删除了它但我有同样的错误),最后一个在com.sun.xml.internal.ws.org.objectweb.asm(jdk 1.7,rt.jar )。 问题是你正在从某个地方引入一个 spring-asm 依赖项(或一个较旧的 spring jar)。执行mvn dependency:tree
并查看哪些spring 版本即将推出。另一种选择是将maven enforcer plugin 与dependency converge rule 一起使用,这可能会触发构建失败。
当我执行“mvn dep:tree”时,只有3.2.3.RELEASE版本的spring jars,我没有asm了。今晚我会按照你的建议去做(收敛,执行者)。谢谢以上是关于spring (data, mvc, security) 依赖项:IncompatibleClassChangeError的主要内容,如果未能解决你的问题,请参考以下文章
使用 spring-data-jpa 和 spring-mvc 过滤数据库行
如何在 Spring MVC 控制器中接收 multipart/form-data?