0

everyone! Something has confused me a lot. I make a Restful Web service based on CXF,but it does not work.

My web.xml is as follows:

  <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>

and then is my 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>

and my HandleRequest.java file presents below:

@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;

}

}

The TestDAO.java file

   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");
  }

I deploy the program in tomcat named CXFSpring. I don't know where is wrong, Everytime I make a request to localhost:8080/CXFSpring/test/Spring, It just return a 404 status. Could you tell me Where is wrong?

cjmandlulu
  • 163
  • 1
  • 2
  • 6

1 Answers1

0

you CXF serving servlet is mapped to /service/*

try the following URL: localhost:8080/CXFSpring/service/test/Spring

WeMakeSoftware
  • 9,039
  • 5
  • 34
  • 52
  • I try it again ,but it's still wrong.But I noticed that when the tomcat start,it says that geronimo-servlet_3.0_spec-1.0.jar is not loaded, I have googled for this, but the answers are not suit for my problem. – cjmandlulu May 29 '13 at 12:30
  • OK, can you confirm that the application is deployed? – WeMakeSoftware May 29 '13 at 13:13
  • Every time I edit the program, I will redeploy the tomcat.I think I should learn something about the CXF first.The code above is from Internet,I want to run it so that I can learn it faster,I've already compared several codes and the xmls,but I still can not figure out where is wrong – cjmandlulu May 29 '13 at 13:56
  • Thank you for your help,I've solved my problem. I think I place my xml at wrong folder.I then move the applicationContext.xml tothe src,and web.xml to the WEB-INF, redeploy the program,and it runs well. – cjmandlulu May 30 '13 at 01:23