在wildfly中实例化ClientBuilder期间的ClassCastException

时间:2015-08-31 13:57:30

标签: java spring maven war resteasy

我有一个正在部署到wildfly 8.1.0 Final的网络应用程序。它使用Spring,RESTEasy等。在代码中的一个位置,创建ClientBuilder需要javax.ws.rs.client.Client

   public class CustomClientImpl implements CustomClient {
      // [...]
      private Client client = ClientBuilder.newClient();
      // [...]
   }

这会生成以下嵌套异常(跳过前5)。简而言之,错误是来自

的失败演员
  

罐:文件:/ C:/Programs/wildfly-8.1.0.Final/modules/system/layers/base/javax/ws/rs/api/main/jaxrs-api-3.0.8.Final.jar !/javax/ws/rs/client/ClientBuilder.class

     

     

VFS:/ C:/Programs/wildfly-8.1.0.Final/bin/content/ybsearch.war/WEB-INF/lib/jaxrs-api-3.0.8.Final.jar/javax/ws/rs /client/ClientBuilder.class

看起来它们应该是兼容的,因为它是相同jar文件中的同一个类。 [??]

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.lilblackbook.search.api.response.ListingProcessorImpl]: Constructor threw exception; nested exception is java.lang.LinkageError: ClassCastException: attempting to cast jar:file:/c:/Programs/wildfly-8.1.0.Final/modules/system/layers/base/javax/ws/rs/api/main/jaxrs-api-3.0.8.Final.jar!/javax/ws/rs/client/ClientBuilder.class to vfs:/c:/Programs/wildfly-8.1.0.Final/bin/content/ybsearch.war/WEB-INF/lib/jaxrs-api-3.0.8.Final.jar/javax/ws/rs/client/ClientBuilder.class
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:267)
        ... 59 more
Caused by: java.lang.LinkageError: ClassCastException: attempting to cast jar:file:/c:/Programs/wildfly-8.1.0.Final/modules/system/layers/base/javax/ws/rs/api/main/jaxrs-api-3.0.8.Final.jar!/javax/ws/rs/client/ClientBuilder.class to vfs:/c:/Programs/wildfly-8.1.0.Final/bin/content/ybsearch.war/WEB-INF/lib/jaxrs-api-3.0.8.Final.jar/javax/ws/rs/client/ClientBuilder.class
        at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:97)
        at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
        at com.lilblackbook.search.api.skynet.CustomClientImpl.<init>(CustomClientImpl.java:56)
        at com.lilblackbook.search.api.response.ListingProcessorImpl.<init>(ListingProcessorImpl.java:38)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_21]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_21]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_21]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525) [rt.jar:1.7.0_21]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)

我的pom包含

的依赖关系
  <dependency>
     <groupId>org.jboss.resteasy</groupId>
     <artifactId>jaxrs-api</artifactId>
     <version>3.0.8.Final</version>
     <!--scope>provided</scope-->
  </dependency>

鉴于jaxrs-api-3.0.8.Final.jar由wildfly提供,我尝试provided作为依赖范围,但生成ClassNotFoundException。当我包含它时,会生成上面详述的ClassCastException

这是否足够信息?有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:0)

要解决此错误,我必须更改用于JaxRS Client的实现。

我从泽西岛去了

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>3.0.0-M6</version>
    <scope>test</scope>
</dependency>

到Smallrye:

<dependency>
   <groupId>io.smallrye</groupId>
   <artifactId>smallrye-rest-client</artifactId>
   <version>1.2.2</version>
</dependency>