CXF-RS抛出找不到与操作匹配请求路径/ create的操作,

问题描述:

我使用CXF框架开发了JAX-RS webservices,并且我部署在Jboss6中。 虽然我尝试使用以下URL http://localhost:8080/UPCServiceLayer/services/upcLineOfBusiness/create从我的HTML页面来访问应用程序(使用POST方法只)我在服务器控制台CXF-RS抛出找不到与操作匹配请求路径/ create的操作,

No operation matching request path /create is found,

下得到下面的错误是我cxf.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd 
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> 
    <import resource="classpath:META-INF/cxf/cxf.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 
    <import resource="classpath:../upc-spring-dao.xml" /> 
    <jaxrs:server id="upcLineOfBusinessRestServiceServer" address="/upcLineOfBusiness"> 
     <jaxrs:serviceBeans> 
      <ref bean="upcLineOfBusinessRestService" /> 
     </jaxrs:serviceBeans> 
    </jaxrs:server> 
    <bean id="upcLineOfBusinessRestService" 
     class="com.tecnotree.upc.services.restservices.impl.UpcLineOfBusinessRestServiceImpl"> 
     <property name="upcLineOfBusinessDao"> 
      <ref bean="upcLineOfBusinessDao" /> 
     </property> 
     <property name="upcUserDao"> 
      <ref bean="upcUserDao" /> 
     </property> 
    </bean> 
</beans> 

下面是我的资源类

@Path("/") 
public classUpcLineOfBusinessRestService { 
    @POST 
    @ConsumeMime("application/xml") 
    @ProduceMime("application/xml") 
    @Path("/create") 
    public UpcLineOfBusinessEntity createUpcLineOfBusinessEntity(
      UpcLineOfBusinessEntity upcLineOfBusinessEntity) 
      throws GenericUpcException 

和我在web.xml文件中声明CXF的servlet也。

<servlet> 
      <servlet-name>CXFServlet</servlet-name> 
      <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 
      <load-on-startup>1</load-on-startup> 
     </servlet> 
     <servlet-mapping> 
      <servlet-name>CXFServlet</servlet-name> 
      <url-pattern>/services/*</url-pattern> 
     </servlet-mapping> 

请帮我

我有些惊讶地看到那里有@ProduceMime@ConsumeMime注释;目前的风格是使用@Produces@Consumes代替(来自JAX-RS标准)。这很重要,因为CXF使用内容类型注释作为其方法匹配过程的一部分,这可能会使事情无法匹配(并因此产生令人困惑的错误消息)。 (另外,你确定你在向服务器发送“application/xml”吗?得到这个错误,你也会有不匹配的错误。尝试调高服务器上的日志级别以查看它的实际内容在匹配期间尝试做;这有助于跟踪这类问题,但不能在默认情况下,因为它是非常唠叨。)

+1

谢谢您的回答。我使用@ProduceMime的原因是Jboss6与cxf2.3.1捆绑在一起,在这个版本中我只能使用jsr311-api-0.8-1.3.0.jar。这个jar文件只有MIME类型的旧类。如何将数据发布为application/xml?我需要将该HTML页面的内容类型设置为application/xml?在这里,我使用纯HTML表单来发布数据。 – Dilip 2012-01-31 10:22:44

+0

暂时我只是将Consumes注释值更改为application/x-www-form-urlencoded。之后,我试图使用HTML表单POST方法调用该资源,但我得到一个新的异常没有消息正文读取器找到请求类:UpcLineOfBusinessEntity,ContentType:应用程序/ x-www-form-urlencoded。基于谷歌我明白,我们需要在CXF中配置JAXB。所以我在cxf.xml中添加了以下代码...... – Dilip 2012-01-31 11:06:58

+0

\t \t \t \t \t \t \t \t \t 真 \t \t \t但我正在逐渐同样的异常。请帮我 – Dilip 2012-01-31 11:07:19

这四行看行对我说:

<url-pattern>/services/*</url-pattern> 

<jaxrs:server id="upcLineOfBusinessRestServiceServer" address="/upcLineOfBusiness"> 

@Path("/") 

@Path("/create") 

Togehter他们应该匹配/services/upcLineOfBusiness/create

+0

感谢您的快速答案。如果我尝试打开一个WADL文件http:// localhost:8080/UPCServiceLayer/services/upcLineOfBusiness?_wadl&_type = xml我收到以下异常15:36:55,206 WARN [org.apache.cxf.jaxrs.utils.JAXRSUtils]。没有找到匹配请求路径/的操作,ContentType:*/*,Accept:text/html,application/xhtml + xml,application/xml; q = 0.9,*/*; q = 0.8。 15:36:55,231 WARN [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] WebApplicationException已被捕获:无可用原因 – Dilip 2012-01-31 10:08:03