我是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错误。
答案 0 :(得分:0)
Rest端点应区分大小写,假设您的项目设置正确(签出Order
服务实现,因为我在OP中看不到它),您应该访问以下端点:
而不是:
请注意顺序路径中的 O 大写字母