无法调用rest cxf服务

我是RESTful服务的新手,我按照教程here .

我的部署描述符web.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
   <display-name>RestDemo</display-name>
   <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:com/example/rest/cxf.xml</param-value>
   </context-param>
   <listener> 
     <listener-class>
       org.springframework.web.context.ContextLoaderListener
     </listener-class>
   </listener>
   <servlet>
     <servlet-name>CXFServlet</servlet-name>
       <servlet-class>
         org.apache.cxf.transport.servlet.CXFServlet
       </servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>CXFServlet</servlet-name>
     <url-pattern>/services/*</url-pattern>
   </servlet-mapping>
</web-app>

cxf.xml描述符:

<beans xmlns:jaxrs="http://cxf.apache.org/jaxrs"   
       xmlns:util="http://www.springframework.org/schema/util"          
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns="http://www.springframework.org/schema/beans"   
       xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans.xsd
             http://www.springframework.org/schema/util
             http://www.springframework.org/schema/util/spring-util-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-servlet.xml" />
  <jaxrs:server address="/" id="connectionService">
    <jaxrs:serviceBeans>
      <ref bean="order"/>
    </jaxrs:serviceBeans>
    <jaxrs:extensionMappings>
      <entry key="xml" value="application/xml">
      </entry>
    </jaxrs:extensionMappings>
  </jaxrs:server>
  <bean class="com.example.rest.OrderInfoImpl" id="order"></bean>
</beans>

我的休息服务 Interface OrderInfo.java:

package com.example.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/Order/")
public interface OrderInfo {

  @GET
  @Produces("application/xml")
  @Path("{orderId}")
  public Order getOrder(@PathParam("orderId") int officeId);

  @GET
  @Produces("application/xml")
  @Path("All")
  public OrderList getAllOrders();

}

实现OrderInfoImpl.java .

当我尝试运行localhost:8080 / RestDemo / services?_ wadl,localhost:8080 / RestDemo / services / order / 1我得到 404 Error .

回答(1)

3 years ago

Rest endpoints 应区分大小写,假设您的项目设置正确(检查您 Order 服务实现,因为我在OP中看不到它),您应该访问以下 endpoints :

  • localhost:8080 / RestDemo / services / Order / 1

代替:

  • localhost:8080 / RestDemo / services / order / 1

请注意订单路径中的 O 大写字母