0

我正在开发spring mvc和jersey rest客户端项目1和项目2作为spring核心。在tomcat服务器中执行代码时抛出异常。

异常:捕获 throwable 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>
4

1 回答 1

0

你在这两个项目中都有球衣。这将使不同的类加载器加载 jersy 类,因此您将获得类转换异常。确保球衣只加载一次。您可以通过将 jersy jar 放入服务器库并使用提供的 maven 范围来做到这一点。

于 2017-04-26T12:08:25.773 回答