Hello,

I am going to testing Jax-RS with ApacheCXF-2.7.0 under Tomcat 6.0.x +
Spring.

The Jax-WS works fine but the configuration of Jax-RS seems not working.

I am not sure if I missed something in the configurations. Please help if I
missed something.


web.xml

>
>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns="
http://java.sun.com/xml/ns/javaee"; xmlns:web="
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"; xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"; id="WebApp_ID"
version="2.5">
  <display-name>TestCXF</display-name>


  <display-name>CXF</display-name>
    <description>CXF Application</description>

      <servlet>
        <servlet-name>CXFServlet-JaxRS</servlet-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <init-param>
           <param-name>config-location</param-name>
           <param-value>/WEB-INF/resources.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>CXFServlet-JaxRS</servlet-name>
        <url-pattern>/resources/*</url-pattern>
      </servlet-mapping>

</web-app>



>


resources.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="userService" address="/userService">
        <jaxrs:serviceBeans>
            <ref bean="customerBean" />
        </jaxrs:serviceBeans>
    </jaxrs:server>

  <bean id="customerBean" class="test.service.UserService" />
</beans>


>




>
package test.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/user")
public class UserService {
    @GET
    @Path("/echo/{msg}")
    public String echo(@PathParam("msg") String msg) {
        System.out.println("Echo: " + msg);

        return "Server: " + msg;
    }
}



>

Reply via email to