2014-08-31 59 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