java.lang.IncompatibleClassChangeError:class org.springframework.core.type.classreading.ClassMetadataReadingVisitor

时间:2016-03-06 09:40:30

标签: java spring-mvc spring-security jqgrid spring-data-jpa

我正在通过链接:https://github.com/nurkiewicz/books中的相同示例开发Spring MVC JQGrid示例。当我部署此代码时,我发现以下错误即将发生。

参考错误:

java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
    at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_45]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_45]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_45]
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957) ~[catalina.jar:7.0.59]
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210) ~[catalina.jar:7.0.59]
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690) ~[catalina.jar:7.0.59]
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ~[catalina.jar:7.0.59]
    at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_45]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_45]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_45]
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957) ~[catalina.jar:7.0.59]
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210) ~[catalina.jar:7.0.59]
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690) ~[catalina.jar:7.0.59]
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ~[catalina.jar:7.0.59]
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:63) ~[spring-core-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) ~[spring-core-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102) ~[spring-core-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:266) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]

当我搜索此错误时,我找到BeanDefinitionStoreException Failed to read candidate component class,但此链接的解决方案对我没有用。 请帮助解决此问题。

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.blogspot.nurkiewicz</groupId>
    <artifactId>books</artifactId>
    <name>jqGrid CRUD</name>
    <description>jqGrid CRUD with Spring MVC backend</description>
    <packaging>war</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <java.version>1.7</java.version>
        <org.springframework.version>3.2.3.RELEASE</org.springframework.version>
        <org.springframework-security.version>3.1.4.RELEASE</org.springframework-security.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

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

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.3.2.RELEASE</version>
        </dependency>

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

        <!-- <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Draft-16</version>
        </dependency> -->

        <!-- CGLIB -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.0</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.13</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>14.0.1</version>
        </dependency>

        <!-- Jackson JSON Mapper -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.11</version>
        </dependency>


        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-assert-core</artifactId>
            <version>2.0M10</version>
            <scope>test</scope>
        </dependency>


        <!-- Persistence -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.172</version>
        </dependency>


        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.flyway</groupId>
            <artifactId>flyway-core</artifactId>
            <version>2.1.1</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>books</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

4 个答案:

答案 0 :(得分:4)

这是因为你在classpath中有不同版本的Spring jar文件。

我首先建议您使用最新的Spring 3.2.x系列补丁:

<org.springframework.version>3.2.16.RELEASE</org.springframework.version>

然后使用Spring框架“Bill Of Materials”来对齐版本:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-framework-bom</artifactId>
      <version>${org.springframework.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

您可以使用${org.springframework.version}删除其他行。

答案 1 :(得分:2)

您的stacktrace表示Java 8字节码。在这种情况下升级到Spring版本4或更高版本

答案 2 :(得分:0)

如果您在应用程序中使用新的spring-core jar和旧的spring-asm jar,则会发生此异常。我面临同样的问题,因为我的弹簧罐是4.2,而spring-asm最新是3.1.4。 您可以从库中删除spring-asm jar。您的应用程序完美无缺 在例外情况下,您也可以清楚地看到&#34;接口org.springframework.asm.ClassVisitor为超类&#34; 试试!!

答案 3 :(得分:-1)

您应该使用 JDK 7 来编译此项目。