java.lang.NoSuchMethodError:javax.ws.rs.core.Response.readEntity

时间:2016-01-12 07:25:10

标签: java rest jboss resteasy

我在做什么

Previosly我正在使用Jercey Client,但Jercey没有机制叫做 Retry 我必须使用RestEasy客户端,所以我在pom.xml文件中添加了以下依赖项

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.0.8.Final</version>
        </dependency>
        <!-- JAXB support -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxb-provider</artifactId>
            <version>3.0.8.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>3.0.8.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>3.0.8.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-atom-provider</artifactId>
            <version>3.0.8.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>3.0.8.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-links</artifactId>
            <version>3.0.8.Final</version>
        </dependency>
         <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
             <version>3.0.8.Final</version>
        </dependency>

我编写的Java代码

 ResteasyClient client;
   client = new ResteasyClientBuilder().build();
   ResteasyWebTarget target = client.target(usersRequest.getUrl());
   Response  response = null;
   if(null != usersRequest.getXmlObject()){
   response =  target.request().accept(MediaType.APPLICATION_XML_TYPE).post(Entity.entity(usersRequest.getXmlObject(),MediaType.TEXT_XML));

   }else{
   response =  target.request().accept(MediaType.APPLICATION_XML_TYPE).get();
           }
   output = response.readEntity(String.class);

但我以下面的错误结束

  

java.lang.NoSuchMethodError:   javax.ws.rs.core.Response.readEntity(Ljava /郎/类;)Ljava /郎/对象;     在   com.alu.ipprd.mdf.soa.portal.integration.restapi.RestAPIUsersFacade.getAuthorizationUserRole(RestAPIUsersFacade.java:212)   [mdf-portal-integration-0.0.1-SNAPSHOT.jar:] at   com.alu.ipprd.bsm.soa.portal.business.aaa.UsersWorkOrder.processBusinessLogic(UsersWorkOrder.java:57)   [mdf-portal-business-0.0.1-SNAPSHOT.jar:] at   com.alu.ipprd.bsm.soa.portal.business.aaa.UsersWorkOrder.processBusinessLogic(UsersWorkOrder.java:1)   [mdf-portal-business-0.0.1-SNAPSHOT.jar:] at   com.alu.ipprd.bsm.soa.portal.common.business.BaseWorkOrder.submitWorkOrder(BaseWorkOrder.java:75)   [mdf-portal-common-0.0.1-SNAPSHOT.jar:] at   com.alu.ipprd.bsm.soa.portal.bean.LoginBean.doLogin(LoginBean.java:907)   [班级:] at   com.alu.ipprd.bsm.soa.portal.bean.LoginBean.verifyLogged(LoginBean.java:1150)   [classes:] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native   方法)[rt.jar:1.7.0_79] at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)   [rt.jar:1.7.0_79] at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)   [rt.jar:1.7.0_79]在java.lang.reflect.Method.invoke(未知来源)   [rt.jar:1.7.0_79] at   org.apache.el.parser.AstValue.invoke(AstValue.java:262)   [jbossweb-7.0.10.Final.jar:] at   org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)   [jbossweb-7.0.10.Final.jar:] at   com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   javax.faces.component.UIComponent $ ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2464)   [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final] at   javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)   [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final] at   com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2168)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2116)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:288)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:246)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)   [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT] at   javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)   [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)   [jbossweb-7.0.10.Final.jar:] at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)   [jbossweb-7.0.10.Final.jar:] at   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)   [jbossweb-7.0.10.Final.jar:] at   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)   [jbossweb-7.0.10.Final.jar:] at   org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154)   [jboss-as-web-7.1.0.Final.jar:7.1.0.Final] at   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)   [jbossweb-7.0.10.Final.jar:] at   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)   [jbossweb-7.0.10.Final.jar:] at   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)   [jbossweb-7.0.10.Final.jar:] at   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)   [jbossweb-7.0.10.Final.jar:] at   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)   [jbossweb-7.0.10.Final.jar:] at   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:671)   [jbossweb-7.0.10.Final.jar:] at   org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:930)   java.lang.Thread.run上的[jbossweb-7.0.10.Final.jar:](未知来源)   [rt.jar中:1.7.0_79]

我还检查了包含此类和方法的jar jaxrs-api-3.0.8.Final.jar,即使这样它也无法解决。谁能告诉我我做错了什么?

编辑1: - 我通过在jboss-deployment-structure.xml

中添加以下条目来限制Jboss使用resteasy jar
<jboss-deployment-structure>
    <deployment>

        <exclusions>
            <module name="org.apache.log4j" />
            <module name="org.jboss.resteasy.resteasy-atom-provider" />
            <module name="org.jboss.resteasy.resteasy-cdi" />
            <module name="org.jboss.resteasy.resteasy-jaxb-provider" />
            <module name="org.jboss.resteasy.resteasy-jaxrs" />
            <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.jboss.resteasy.resteasy-jackson-provider" />
            <module name="org.javassist" />
        </exclusions>
        <dependencies>
            <module name="javaee.api">
                <imports>
                    <exclude path="org/apache/xml/security/**" />
                </imports>
            </module>

            <module name="org.jboss.resteasy.resteasy-jettison-provider" />
            <module name="org.codehaus.jettison" /> 
        </dependencies>
    </deployment>
</jboss-deployment-structure>

2 个答案:

答案 0 :(得分:1)

由于您的应用程序和Jboss之间的Resteasy客户端实现版本不同,会引发此问题。

请参阅RESTEasy Client + NoSuchMethodError

答案 1 :(得分:0)

这个RESTEasy Client + NoSuchMethodError将如何帮助解决问题。当我解压缩resteasy-jaxrs-3.0.8.Final-all时我正在使用Jboss7.1.0.final服务器它有resteasy-jboss-modules-3.0.8.Finalresteasy-jboss-modules-3.0.8.Final来最多使用三个文件夹comjavaxorg这三个文件夹我们必须复制并粘贴到jboss-as-7.1.0.Final\jboss-as-7.1.0.Final\modules

我只将resteasy-jboss-modules-3.0.8.Final\org\jboss\resteasy复制到Jboss服务器,因此失败了。