RESTEasy 客户端 + NoSuchMethodError [英] RESTEasy Client + NoSuchMethodError

查看:36
本文介绍了RESTEasy 客户端 + NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写简单的 RESTEasy 客户端.下面给出的是示例代码:

Client client = ClientBuilder.newBuilder().build();WebTarget target = client.target("http://localhost:8080/context/path");响应 response = target.request().post(Entity.entity(object, "application/json"));//读取字符串格式的输出字符串值 = 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.(Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)V16:07:57,679 错误 [stderr] (http-localhost/127.0.0.1:8080-1) 在 org.jboss.resteasy.client.jaxrs.internal.ClientConfiguration.(ClientConfiguration.java:44)16:07:57,680 错误 [stderr] (http-localhost/127.0.0.1:8080-1) 在 org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:317)16:07:57,680 错误 [stderr] (http-localhost/127.0.0.1:8080-1) 在 org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:49)

我在 pom.xml 中添加了 resteasy 客户端依赖:

 <依赖><groupId>org.jboss.resteasy</groupId><artifactId>resteasy-client</artifactId><version>3.0.8.Final</version></依赖>

我的代码部署在 JBOSS EAP 6.1 上.JDK 版本为 1.7.

更新:我还尝试在我的 pom 中添加 resteasy jax-rs 依赖项.我还通过在 web.xml 中添加以下行来验证是否启用了 ResteasyProviderFactory:

 <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class></监听器>

请在下面找到 maven 依赖项列表:

<依赖><groupId>org.jboss.spec.javax.ejb</groupId><artifactId>jboss-ejb-api_3.1_spec</artifactId><范围>提供</范围></依赖><依赖><groupId>javax.enterprise</groupId><artifactId>cdi-api</artifactId><范围>提供</范围></依赖><依赖><groupId>org.hibernate.javax.persistence</groupId><artifactId>hibernate-jpa-2.0-api</artifactId><范围>提供</范围></依赖><依赖><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId><范围>提供</范围></依赖><依赖><groupId>org.jboss.resteasy</groupId><artifactId>resteasy-jaxrs</artifactId><version>3.0.8.Final</version><范围>提供</范围></依赖><依赖><groupId>org.jboss.resteasy</groupId><artifactId>resteasy-client</artifactId><version>3.0.8.Final</version></依赖><依赖><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.2.4</version></依赖><依赖><groupId>junit</groupId><artifactId>junit</artifactId><范围>测试</范围></依赖><依赖><groupId>org.jboss.arquillian.junit</groupId><artifactId>arquillian-junit-container</artifactId><范围>测试</范围></依赖><依赖><groupId>org.jboss.arquillian.protocol</groupId><artifactId>arquillian-protocol-servlet</artifactId><范围>测试</范围></依赖></依赖项>

但它不起作用.

从异常中,我无法弄清楚缺少什么.我无法在 SO 或任何其他论坛上找到有关此问题的任何参考资料.如果您之前看到过这个问题并且知道如何解决,请告诉我.谢谢.

<小时>

2014 年 6 月 11 日更新:

参考后这个博客 并通过排除一些 resteasy 和 jackson 模块,我尝试创建类似的 jboss-deployment-structure.xml 并将其保存在我的 EJB 项目的 META-INF 文件夹中.这解决了我的org.jboss.resteasy.spi.ResteasyProviderFactory.(Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)"的 NoSuchMethodError 问题.我的 jboss-deployment-structure.xml 的结构是:

但现在我看到其他方法的类似异常:

Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object;在 com.example.data.DemoProxyBean.callDemoTx(DemoProxyBean.java:59) [demo-service.jar:]在 com.example.data.DemoProxyBean$Proxy$_$$_WeldClientProxy.callDemoTx(DemoProxyBean$Proxy$_$$_WeldClientProxy.java) [demo-service.jar:]

我在一行看到这个异常:

String value = response.readEntity(String.class);

奇怪的是,当我检查response.readEntity(String.class)"时,在调试时,我可以看到字符串值.但是当我尝试转到下一行时,我看到了这个错误.你能指导我吗,可能是什么问题?

进一步更新:

我参考了这个 JBOSS 问题跟踪器.但它与 WildFly 相关,而不是 EAP 服务器.它要求我们排除模块javaee-api".我尝试排除javaee-api"模块,但它也不起作用.

解决方案

终于在我的头上敲了几天,我可以解决这些问题.

<小时>

问题 1 的解决方案:

<块引用><块引用>

错误:java.lang.NoSuchMethodError:org.jboss.resteasy.spi.ResteasyProviderFactory.(Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)"

解决方案:我通过在 jboss-deployment-structure.xml 中的排除列表中添加更多 resteasy 模块解决了这个问题.我目前的 jboss-deployment-structure.xml 状态如下:

我相信,它可以通过简单地排除模块org.jboss.resteasy.resteasy-jaxrs"和org.jboss.resteasy.resteasy-cdi"来工作.但我没有进一步尝试,因为我面临另一个问题.您可以尝试删除不必要的排除项.

问题 2 的解决方案:

<块引用>

错误:Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object;"

解决方案: JBOSS EAP 6.1 与默认的 resteasy 发行版捆绑在一起.我从 位置.

它带有名为 resteasy-jboss-modules-3.0.7.Final.zip 的 zip 文件.在 JBoss EAP 6.1 发行版的 modules/system/layers/base/目录中解压这个文件.这将覆盖那里的一些现有文件.这将解决第二个问题.

希望这些信息对其他人有帮助.

I am trying to write simple RESTEasy client. Below given is sample code:

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);

I get exception at line:

Client client = ClientBuilder.newBuilder().build();

I see following errors in my console:

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)

I have added resteasy client dependancy in pom.xml as:

  <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-client</artifactId>
      <version>3.0.8.Final</version>
  </dependency>

My code is deployed on JBOSS EAP 6.1. JDK version is 1.7.

Update: I also tried adding resteasy jax-rs dependancy in my pom. I also verified if ResteasyProviderFactory is enabled by adding following lines in my web.xml:

  <listener>
    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
  </listener>

Please find below list of maven dependancies:

<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>

But it doesnt work.

From exception, I am not able to figure out what is missing. I am not able to find any references for this issue on SO or any other forums. Please let me know, if you have seen this issue earlier and you know how to fix it. Thanks.


Update 11 June 2014:

After referring this blog and by excluding some resteasy and jackson modules, I tried creating similar jboss-deployment-structure.xml and keeping it in META-INF folder in my EJB project. This solved my issue of NoSuchMethodError for "org.jboss.resteasy.spi.ResteasyProviderFactory.(Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)" . Structure of my jboss-deployment-structure.xml is:

<?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>

But now I see similar exception for other method:

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:]

And I see this exception at line:

String value = response.readEntity(String.class);

Weird thing is that, when I inspect "response.readEntity(String.class)", while debugging, I can see the String value. But when I try to go to step to next line, I see this error. Can you please guide me, what could be the issue?

Further update:

I referred to this JBOSS Issue tracker. But it was related to WildFly, and not EAP server. It asks us to exclude module "javaee-api". I tried excluding "javaee-api" module, but it also does not work.

解决方案

At last after banging my head for couple of days, I could resolve these issues.


Solution for issue 1:

Error: "java.lang.NoSuchMethodError: org.jboss.resteasy.spi.ResteasyProviderFactory.(Lorg/jboss/resteasy/spi/ResteasyProviderFactory;)"

Solution: I resolved this issue, by adding more resteasy modules in exclusion list inside jboss-deployment-structure.xml. My current state of jboss-deployment-structure.xml is as:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
   <deployment>
      <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson-provider" services="import"/>
       </dependencies>
       <exclude-subsystems>
           <subsystem name="resteasy"/>
       </exclude-subsystems>
     <exclusions>
        <module name="javax.activation.api"/>
        <module name="javax.annotation.api"/>
        <module name="javax.ejb.api"/>
        <module name="javax.el.api"/>
        <module name="javax.enterprise.api"/>
        <module name="javax.enterprise.deploy.api"/>
        <module name="javax.inject.api"/>
        <module name="javax.interceptor.api"/>
        <module name="javax.jms.api"/>
        <module name="javax.jws.api"/>
        <module name="javax.mail.api"/>
        <module name="javax.management.j2ee.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.resource.api"/>
        <module name="javax.rmi.api"/>
        <module name="javax.security.auth.message.api"/>
        <module name="javax.security.jacc.api"/>
        <module name="javax.servlet.api"/>
        <module name="javax.servlet.jsp.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.ws.rs.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="javax.xml.registry.api"/>
        <module name="javax.xml.soap.api"/>
        <module name="javax.xml.ws.api"/>

        <!-- This one always goes last. -->
        <module name="javax.api"/>

       <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.resteasy-jackson2-provider"/>
       <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"/>
       <module name="javax.ws.rs.core"/>
     </exclusions>
   </deployment>
 </jboss-deployment-structure>

I believe, it could have worked by simply excluding modules "org.jboss.resteasy.resteasy-jaxrs" and "org.jboss.resteasy.resteasy-cdi". But I did not try further as I faced another issue. You can try by removing un-necessary exclusions.

Solution for issue 2:

Error: "Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.Response.readEntity(Ljava/lang/Class;)Ljava/lang/Object;"

Solution: JBOSS EAP 6.1, is bundled with default resteasy distribution. I downloaded latest resteasy jax-rs implementation (resteasy-jaxrs-3.0.7.Final-all.zip) from location.

It comes with zip file called resteasy-jboss-modules-3.0.7.Final.zip. Unzip this file inside modules/system/layers/base/ directory of the JBoss EAP 6.1 distribution. This will overwrite some of the existing files there. This will resolve second issue.

Hope this information would help others.

这篇关于RESTEasy 客户端 + NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆