【问题标题】:CXF-RS throwing No operation matching request path /create is found,CXF-RS 抛出 No operation matching request path /create is found,
【发布时间】:2012-01-31 09:49:55
【问题描述】:

我使用 CXF 框架开发了 JAX-RS Web 服务,并部署在 Jboss6 中。 当我尝试使用我的 HTML 页面中的以下 URL http://localhost:8080/UPCServiceLayer/services/upcLineOfBusiness/create 访问应用程序时(仅使用 POST 方法),我在服务器控制台中收到以下错误

没有找到匹配请求路径/create的操作,

以下是我的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>

请帮帮我

【问题讨论】:

    标签: web-services rest cxf


    【解决方案1】:

    在那里看到@ProduceMime@ConsumeMime 注释让我有些惊讶;当前的样式是使用 @Produces@Consumes 代替(来自 JAX-RS 标准)。这很重要,因为 CXF 使用内容类型注释作为其方法匹配过程的一部分,这可能会导致匹配失败(并因此给出令人困惑的错误消息)。

    (另外,您确定要在服务器上发布“application/xml”吗?弄错了,您也会遇到不匹配错误。尝试调高服务器上的登录级别以查看其内容实际上在匹配过程中尝试这样做;这有助于追踪此类问题,但默认情况下无法打开,因为它非常很健谈。)

    【讨论】:

    • 感谢您的回答。我使用 @ProduceMime 的原因是 Jboss6 与 cxf2.3.1 捆绑在一起,在这个版本中我只能使用 jsr311-api-0.8-1.3.0.jar 。这个 jar 文件只有 MIME 类型的旧类。如何将数据发布为 application/xml ?我需要将该 HTML 页面的内容类型设置为 application/xml?这里我使用纯 HTML 表单来发布数据。
    • 暂时我只是将 Consumes 注释值更改为 application/x-www-form-urlencoded 。之后,我尝试使用 HTML 表单 POST 方法调用该资源,但我得到一个新的异常没有为请求类找到消息正文阅读器:UpcLineOfBusinessEntity,ContentType:application/x-www-form-urlencoded。基于谷歌,我知道我们需要在 CXF 中配置 JAXB。所以我在 cxf.xml 中添加了以下行......
    • true 但我我得到了同样的例外。请帮帮我
    【解决方案2】:

    我觉得这四行没问题:

    <url-pattern>/services/*</url-pattern>
    
    <jaxrs:server id="upcLineOfBusinessRestServiceServer" address="/upcLineOfBusiness">
    
    @Path("/")
    
    @Path("/create")
    

    它们应该匹配/services/upcLineOfBusiness/create

    【讨论】:

    • 感谢您的快速回答。如果我尝试打开一个 WADL 文件 localhost:8080/UPCServiceLayer/services/… 我得到以下异常 15:36:55,206 WARN [org.apache.cxf.jaxrs.utils.JAXRSUtils] .No operation matching request path / is found, ContentType : /,接受: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 已被捕获:没有可用的原因
    【解决方案3】:

    确保在调用 API (GET/POST/PUT/DELETE) 时使用了正确的 HTTP 方法

    【讨论】:

      猜你喜欢
      • 2019-02-20
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 2014-12-20
      • 2021-11-13
      相关资源
      最近更新 更多