cxf:找不到 Observer 的请求 url
cxf : can't find request url for Observer
我正在使用 spring 和 Apache CXF 创建一些休息资源。看起来我的 jaxrs bean 没有被初始化。
WARNING: Can't find the the request for
http://localhost:8080/cxf-sandbox/home-screen/v1/12345/predefined-templates/universal_template's
Observer
我在这里错过了什么?
我已将所有请求配置为路由到我的 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>
我已经配置了一个 jaxrs 服务器 bean 和我的 rest 资源 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" />
这是我的休息资源
@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();
}
}
型号
@XmlRootElement(name="employee")
public class Employee {
@XmlElement(name = "name")
private String name;
public Employee(String name) {
super();
this.name = name;
}
}
我未能将我的 CXF servlet 所需的上下文加载为根上下文的一部分,即
<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>
或作为单独的子应用程序上下文的一部分,即
<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>
我正在使用 spring 和 Apache CXF 创建一些休息资源。看起来我的 jaxrs bean 没有被初始化。
WARNING: Can't find the the request for http://localhost:8080/cxf-sandbox/home-screen/v1/12345/predefined-templates/universal_template's Observer
我在这里错过了什么?
我已将所有请求配置为路由到我的 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>
我已经配置了一个 jaxrs 服务器 bean 和我的 rest 资源 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" />
这是我的休息资源
@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();
}
}
型号
@XmlRootElement(name="employee")
public class Employee {
@XmlElement(name = "name")
private String name;
public Employee(String name) {
super();
this.name = name;
}
}
我未能将我的 CXF servlet 所需的上下文加载为根上下文的一部分,即
<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>
或作为单独的子应用程序上下文的一部分,即
<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>