每个人!有些事情让我很困惑。我做了一个基于 CXF 的 Restful Web 服务,但它不起作用。
我的 web.xml 如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.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>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
然后是我的applicationContext.xml:
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="handleRequest" class="test.cjm.HandleReuqst"/> <jaxrs:server id="customerService" address="/">
<jaxrs:serviceBeans>
<ref bean="handleRequest"/>
</jaxrs:serviceBeans>
我的 HandleRequest.java 文件如下所示:
@Produces("application/json")
@Path("/test")
public class HandleRequest {
@GET
@Path("/Spring")
public TestVO testSpring(){
System.out.println("get users:");
TestVO tv = TestDAO.getPerson();
return tv;
}
}
TestDAO.java 文件
private static Map<String,TestVO> testVOs;
static{
testVOs = new HashMap<String,TestVO>();
TestVO t1 = new TestVO();
t1.setId(1);
t1.setName("cjm");
testVOs.put("1", t1);
}
public static TestVO getPerson(){
return testVOs.get("1");
}
我将该程序部署在名为 CXFSpring 的 tomcat 中。我不知道哪里错了,每次我向 localhost:8080/CXFSpring/test/Spring 发出请求时,它只返回一个 404 状态。你能告诉我哪里错了吗?