cxf : can't find request url for Observer

cxf, java, jax-rs, rest, spring

Solution

I had failed to load the required context for my CXF servlet either as a part of the root context, i.e.,

<context-param>
    <description>locations of the Spring configuration files</description>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/CXFServlet-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

or as a part of a seperate child application context, i.e.

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

Problem

I am using spring with Apache CXF to create some rest resources. Looks like my jaxrs beans are not getting intialized. WARNING: Can't find the the request for http://localhost:8080/cxf-sandbox/home-screen/v1/12345/predefined-templates/universal_template's Observer What am I missing here? I've configured for all requests to be routed to my CXF servlet ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>cxf-sandbox</display-name> <context-param> <param-name>log4j.refresh.interval</param-name> <param-value>120</param-value> </context-param> <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>/*</url-pattern> </servlet-mapping> <context-param> <description>locations of the Spring configuration files</description> <param-name>contextConfigLocation</param-name> <param-value> classpath:META-INF/cxf/cxf.xml, classpath:META-INF/cxf/cxf-servlet.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> ``` I've configured a jaxrs server bean and my rest resource bean ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.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="myJaxServer" address="/home-screen"> <jaxrs:serviceBeans> <ref bean="PredefinedHomeScreenResourceImpl" /> </jaxrs:serviceBeans> <jaxrs:providers> <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" /> </jaxrs:providers> </jaxrs:server> <bean id="PredefinedHomeScreenResourceImpl" class="PredefinedHomeScreenResourceImpl" /> ``` This is my rest resource ``` @Path("/v1/{billingId}/predefined-templates") @Produces(MediaType.APPLICATION_JSON) public class PredefinedHomeScreenResourceImpl { private final static Logger LOGGER = LoggerFactory.getLogger(PredefinedHomeScreenResourceImpl.class); @GET @Path("/templateName") public Response getPredefinedTemplate(String billingId, String templateName) { LOGGER.debug("IN HERE"); return Response.ok(new Employee("Abhijith")).build(); } } ``` Model ``` @XmlRootElement(name="employee") public class Employee { @XmlElement(name = "name") private String name; public Employee(String name) { super(); this.name = name; } } ```

Original source