首页 文章

基于CXF的宁静Web服务

提问于
浏览
0

大家!有些东西让我很困惑 . 我基于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");
  }

我在tomcat中部署名为CXFSpring的程序 . 我不知道哪里出错了,每次我向localhost发出请求:8080 / CXFSpring / test / Spring,它只返回404状态 . 你能告诉我哪里错了吗?

1 回答

  • 0

    您的CXF服务servlet映射到 /service/*

    请尝试以下网址: localhost:8080/CXFSpring/service/test/Spring

相关问题