【发布时间】:2015-04-29 16:54:40
【问题描述】:
我尝试在 tomcat 中启动并运行我的第一个 rest 应用程序。我使用 Maven 进行构建过程。构建工作没有任何错误。
Tomcat 提取 rest.war 而不引发错误,我尝试请求 http://hostname:8080/rest/categoryservice/category/01。这会导致 404 响应。我附上了我的 web.xml、beans.xml 和服务类的 sn-p。 pom 仅包含依赖项。我希望您有任何建议或提示来找出错误。
服务等级:
@Path("/categoryservice")
@Produces({"application/json","application/xml"})
public class CategoryService {
@GET
@Path("/category/{id}")
@Produces({"application/json","application/xml"})
public Category getCategory(@PathParam("id") String id) {
...
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-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>/*</url-pattern>
</servlet-mapping>
</web-app>
beans.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: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/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 id="categoryRESTService" address="/">
<jaxrs:serviceBeans>
<ref bean="categoryService" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="categoryService" class="demo.restful.CategoryService">
<property name="categoryDAO">
<ref bean="categoryDAO" />
</property>
</bean>
【问题讨论】:
-
我假设有一个 id 为“01”的类别-否则,请尝试hostname:8080/rest/categoryservice/category/1-tomcat 控制台上是否有任何堆栈跟踪?如果是,请在此处发布。
-
感谢 spring 依赖缺失。但我还有一个问题。我想看看 wadl 文件。我有什么要补充的吗? hostname:8080/rest/categoryservice?_wadl 什么也不返回,hostname:8080/rest?_wadl
标签: spring rest maven tomcat cxf