gpt4 book ai didi

java - 在 Wildfly 中实例化 ClientBuilder 期间的 ClassCastException

转载 作者:行者123 更新时间:2023-12-01 13:49:01 28 4
gpt4 key购买 nike

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

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

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

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



鉴于它们是相同 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上面详细生成。

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

最佳答案

为了解决这个错误,我不得不更改我用于 JaxRS 客户端的实现。
我从 Jersey 去:

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.0.0-M6</version>
<scope>test</scope>
</dependency>
给小莱:
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-rest-client</artifactId>
<version>1.2.2</version>
</dependency>

关于java - 在 Wildfly 中实例化 ClientBuilder 期间的 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32313046/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com