我正在使用JAX-RS& amp;和POST方法开发REST服务。 Apache CXF。部署在Jboss 7.1.1服务器上。当我测试时,我得到的是异常
java.lang.NoSuchMethodError: javax.ws.rs.ClientErrorException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status$Family;)Ljavax/ws/rs/core/Response;
javax.ws.rs.ClientErrorException.<init>(ClientErrorException.java:88)
org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:503)
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:198)
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:90)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:167)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206)
javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)
我使用了以下部署结构
<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<exclusions>
<module name="javaee.api" />
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
<module name="javax.ws.rs.api"/>
</exclusions>
<dependencies>
<module name="javax.activation.api" export="true" />
<module name="javax.annotation.api" export="true" />
<module name="javax.ejb.api" export="true" />
<module name="javax.el.api" export="true" />
<module name="javax.enterprise.api" export="true" />
<module name="javax.enterprise.deploy.api" export="true" />
<module name="javax.inject.api" export="true" />
<module name="javax.interceptor.api" export="true" />
<module name="javax.jms.api" export="true" />
<module name="javax.jws.api" export="true" />
<module name="javax.mail.api" export="true" />
<module name="javax.management.j2ee.api" export="true" />
<module name="javax.persistence.api" export="true" />
<module name="javax.resource.api" export="true" />
<module name="javax.rmi.api" export="true" />
<module name="javax.security.auth.message.api" export="true" />
<module name="javax.security.jacc.api" export="true" />
<module name="javax.servlet.api" export="true" />
<module name="javax.servlet.jsp.api" export="true" />
<module name="javax.transaction.api" export="true" />
<module name="javax.validation.api" export="true" />
// Below two are excluded to resolve duplicate classload issues
<module name="javax.ws.rs.api" optional="true"/>
<module name="javax.xml.crypto.dsig" optional="true"/>
<module name="javax.xml.bind.api" export="true" />
<module name="javax.xml.registry.api" export="true" />
<module name="javax.xml.soap.api" export="true" />
<module name="javax.xml.ws.api" export="true" />
<!-- This one always goes last. -->
<module name="javax.api" export="true" />
</dependencies>
</deployment>
由于apache cxf servlet依赖于javax.ws.rs-api-2.0-m10.jar,所以我排除了具有相同类集的模块javax.ws.rs.api。