java 在 CXF 休息服务中找不到课程的资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26713743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No resource found for class in CXF rest services
提问by kavuru
I am trying to implement restfull webservice using apache cxf.
我正在尝试使用 apache cxf 实现 restfull webservice。
while deploying the war file in tomcat I am getting the error as Error creating bean with name 'Analysis': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
在 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
Below is cxf.xml:
下面是 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:
<?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>
Class Definition:
类定义:
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;
}
}
what else I am missing here?
我在这里还缺少什么?
TIA
TIA
回答by Holly Cummins
Another common cause of this problem is having the method annotated with @Path protected
rather than public
.
此问题的另一个常见原因是使用 @Pathprotected
而不是public
.
回答by Matthias Wuttke
I experienced a similar problem that disappeared when I corrected the @WebService annotation, which needs to be on the interface and not the service class.
我遇到了类似的问题,当我更正@WebService 注解时,该问题消失了,该注解需要在接口上而不是在服务类上。