首页 文章

cxf:无法找到Observer的请求网址

提问于
浏览
2

我正在使用带有Apache CXF的spring来创建一些休息资源 . 看起来我的jaxrs bean没有初始化 .

警告:找不到http:// localhost:8080 / cxf-sandbox / home-screen / v1 / 12345 / predefined-templates / universal_template的观察者的请求

我在这里想念的是什么?

我已将所有请求配置为路由到我的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;
}


}

1 回答

  • -1

    我无法作为根上下文的一部分加载我的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>
    

相关问题