在CXF休息服务中没有为类找到资源

时间:2014-11-03 11:52:49

标签: java spring web-services rest tomcat

我正在尝试使用apache cxf实现restfull webservice。

在tomcat中部署war文件时我得到的错误是创建名为'Analysis'的bean的错误:init方法的调用失败;嵌套异常是org.apache.cxf.service.factory.ServiceConstructionException

INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/cxf.xml]
03-Nov-2014 17:03:40 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12f41a5: defining beans [/Analysis/,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,Analysis,AnalysisResponse,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
03-Nov-2014 17:03:40 org.apache.cxf.jaxrs.utils.ResourceUtils checkMethodDispatcher
WARNING: No resource methods have been found for resource class com.bt.ws.pointsystem.pojo.AnalysisResponse
03-Nov-2014 17:03:40 org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean checkResources
SEVERE: No resource classes found
03-Nov-2014 17:03:40 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@12f41a5: defining beans [/Analysis/,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,Analysis,AnalysisResponse,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
03-Nov-2014 17:03:40 org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed

下面是cxf.xml:

<beans default-autowire="byName" xmlns="http://www.springframework.org/schema/beans"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">

  <context:component-scan base-package="com.bt.ws.pointsystem,com.bt.ws.pointsystem.pojo" />


  <jaxrs:server address="/" id="Analysis">
   <jaxrs:serviceBeans>
              <ref bean="AnalysisResponse" />

   </jaxrs:serviceBeans>
   <jaxrs:extensionMappings>
    <entry key="xml" value="application/xml">
    </entry>
   </jaxrs:extensionMappings>
  </jaxrs:server>
    <bean class="com.bt.ws.pointsystem.pojo.AnalysisResponse" id="AnalysisResponse">
    </bean>
</beans>

的web.xml:

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

 <web-app>
  <display-name>PointSystemService</display-name>

  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>WEB-INF/cxf.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>
  </servlet>
  <servlet-mapping>
   <servlet-name>CXFServlet</servlet-name>

   <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
 </web-app>

班级定义:

package com.bt.ws.pointsystem.pojo;

public class AnalysisResponse {
    private String UserId;
    private String AnalysisType;
    public String getUserId() {
        return UserId;
    }
    public void setUserId(String userId) {
        UserId = userId;
    }
    public String getAnalysisType() {
        return AnalysisType;
    }
    public void setAnalysisType(String analysisType) {
        AnalysisType = analysisType;
    }





}

我在这里还缺少什么?

TIA

2 个答案:

答案 0 :(得分:0)

当我纠正@WebService注释时,我遇到了类似的问题,该注释需要在接口而不是服务类上。

答案 1 :(得分:0)

此问题的另一个常见原因是使用@Path protected而不是public注释该方法。