2014-08-31 79 views
0

我是RESTful服务的新手,我按照教程here无法调用rest cxf服务

我的部署描述符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> 

我的休息服务InterfaceOrderInfo.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

当我试图运行本地主机:8080/RestDemo /服务_wadl本地主机:8080/RestDemo /服务/顺序/ 1我得到404错误

回答

0

剩下的终点应该是区分大小写的,假设你的项目设置正确(结帐你Order服务实现,因为我看不到它在OP),你应该访问以下端点:

  • 本地主机:/ RestDemo//而不是8080服务订单/ 1

  • 本地主机:8080/RestDemo /服务/顺序/ 1

注意在顺序Ø大写字母路径

+0

我曾与本地主机尝试:8080/RestDemo /服务/订单/ 1 ...返回404错误 – crazycoder 2014-08-31 14:58:11

+0

所订购imlementation ? – tmarwen 2014-08-31 19:12:24