RESTEasy Client + NoSuchMethodError
我正在尝试编写简单的 RESTEasy 客户端。下面给出的是示例代码:
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target("http://localhost:8080/context/path");
Response response = target.request().post(Entity.entity(object, "application/json"));
//Read output in string format
String value = response.readEntity(String.class);
我在行中得到异常:
Client client = ClientBuilder.newBuilder().build();
我在控制台中看到以下错误:
16:07:57,678 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) java.lang.NoSuchMethodError: org.jboss.resteasy.spi.ResteasyProviderFactory.<init>(Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)V
16:07:57,679 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) at org.jboss.resteasy.client.jaxrs.internal.ClientConfiguration.<init>(ClientConfiguration.java:44)
16:07:57,680 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:317)
16:07:57,680 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:49)
我在pom中添加了不安的客户端依赖性.xml为:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.8.Final</version>
</dependency>
我的代码部署在 JBOSS EAP 6.1 上。JDK 版本是 1.7。
更新:我还尝试在我的pom中添加不安的jax-rs依赖性。我还通过在我的网络中添加以下行来验证是否启用了ResteasyProviderFactory.xml:
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
请在下面找到专家家属名单:
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.8.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.8.Final</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
但它不起作用。
从例外,我无法弄清楚缺少什么。我无法在SO或任何其他论坛上找到有关此问题的任何参考资料。请让我知道,如果您之前看到此问题并且知道如何解决它。谢谢。
2014 年 6 月 11 日更新:
在引用了这个博客并通过排除一些不安和杰克逊模块之后,我尝试创建类似的jboss-deployment-structure.xml并将其保存在我的EJB项目中的META-INF文件夹中。这解决了我的NoSuchMethodError问题,用于“org.jboss.resteasy.spi.ResteasyProviderFactory”。(Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)“ .我的jboss-deployment-structure的结构.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="resteasy"/>
</exclude-subsystems>
<exclusions>
<!-- <module name="org.apache.log4j" /> -->
<module name="org.apache.commons.logging"/>
<module name="org.jboss.as.jaxrs"/>
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
<module name="org.jboss.resteasy.resteasy-cdi"/>
<!-- <module name="org.jboss.resteasy.jackson-provider"/>
<module name="org.jboss.resteasy.resteasy-atom-provider"/>
<module name="org.jboss.resteasy.resteasy-hibernatevalidator-provider"/>
<module name="org.jboss.resteasy.resteasy-jaxb-provider"/>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
<module name="org.jboss.resteasy.resteasy-jsapi"/>
<module name="org.jboss.resteasy.resteasy-multipart-provider"/>
<module name="org.jboss.resteasy.resteasy-yaml-provider"/>
<module name="org.codehaus.jackson.jackson-core-asl"/>
<module name="org.codehaus.jackson.jackson-jaxrs"/>
<module name="org.codehaus.jackson.jackson-mapper-asl"/>
<module name="org.codehaus.jackson.jackson-xc"/>
<module name="org.codehaus.jettison"/>
<module name="javax.ws.rs.api"/> -->
</exclusions>
</deployment>
</jboss-deployment-structure>
但现在我看到其他方法也有类似的例外:
Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object;
at com.example.data.DemoProxyBean.callDemoTx(DemoProxyBean.java:59) [demo-service.jar:]
at com.example.data.DemoProxyBean$Proxy$_$$_WeldClientProxy.callDemoTx(DemoProxyBean$Proxy$_$$_WeldClientProxy.java) [demo-service.jar:]
我在行中看到这个例外:
String value = response.readEntity(String.class);
奇怪的是,当我在调试时检查“response.readEntity(String.class)”时,我可以看到String值。但是当我尝试转到下一行时,我看到此错误。你能指导我,可能是什么问题吗?
进一步更新:
我提到了这个JBOSS问题跟踪器。但它与WildFly有关,而不是EAP服务器。它要求我们排除模块“javaee-api”。我尝试排除“javaee-api”模块,但它也不起作用。