java.lang.LinkageError: ClassCastException: in spring MVC project
java.lang.LinkageError: ClassCastException: in spring MVC project
我正在 spring mvc 和 jersey rest 客户端项目 1 和项目 2 作为 spring 核心。在 tomcat 服务器中执行代码时抛出异常。
异常:
捕获可抛出的 ClassCastException:试图 castjar:file:/project1/web/webroot/WEB-INF/lib/jersey-core-1.13.jar!/javax/ws/rs/ext/RuntimeDelegate.classtojar:file:/project2/lib/jersey-core-1.13.jar !/javax/ws/rs/ext/RuntimeDelegate.class
java.lang.LinkageError: ClassCastException: 试图 castjar:file:/project1/web/webroot/WEB-INF/lib/jersey-core-1.13.jar!
/javax/ws/rs/ext/RuntimeDelegate.classtojar:file:/project2/lib/jersey-core-1.13.jar!/javax/ws/rs/ext/RuntimeDelegate.class
我的项目 2 maven 依赖项:
<properties>
<jersey.version>1.13</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.4.0</version>
</dependency>
项目 1 maven 依赖项:
<properties>
<jersey.version>1.13</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.0.6.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
您在这两个项目中都有 jersy。这将使不同的 class 加载器加载 jersy class,因此你将得到 class 强制转换异常。确保 jersy 只加载一次。你可以通过将你的 jersy jar 放在服务器库中并使用提供的 maven 范围来做到这一点。
我正在 spring mvc 和 jersey rest 客户端项目 1 和项目 2 作为 spring 核心。在 tomcat 服务器中执行代码时抛出异常。
异常: 捕获可抛出的 ClassCastException:试图 castjar:file:/project1/web/webroot/WEB-INF/lib/jersey-core-1.13.jar!/javax/ws/rs/ext/RuntimeDelegate.classtojar:file:/project2/lib/jersey-core-1.13.jar !/javax/ws/rs/ext/RuntimeDelegate.class java.lang.LinkageError: ClassCastException: 试图 castjar:file:/project1/web/webroot/WEB-INF/lib/jersey-core-1.13.jar! /javax/ws/rs/ext/RuntimeDelegate.classtojar:file:/project2/lib/jersey-core-1.13.jar!/javax/ws/rs/ext/RuntimeDelegate.class
我的项目 2 maven 依赖项:
<properties>
<jersey.version>1.13</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>2.4.0</version>
</dependency>
项目 1 maven 依赖项:
<properties>
<jersey.version>1.13</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.0.6.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
您在这两个项目中都有 jersy。这将使不同的 class 加载器加载 jersy class,因此你将得到 class 强制转换异常。确保 jersy 只加载一次。你可以通过将你的 jersy jar 放在服务器库中并使用提供的 maven 范围来做到这一点。