CXF中,出现 No services have been found.

来源:互联网 发布:淘宝客微信公众号 编辑:程序博客网 时间:2024/06/18 17:24

问题描述:

最近在用CXF开发web service时遇到这个很郁闷的问题。第一次用CXF,先说说我的配置吧。
web.xml文件中
 <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>

cxf配置文件中

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<!-- CXF webservice配置 -->
<import resource="classpath:META-INF/cxf/cxf.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  

<bean id="fyqqRespServiceImpl" class="com.thunisoft.fy.gxpt.server.webservice.service.impl.FyqqRespServiceImpl"/>  
<jaxws:endpoint  
  id="fyqqResp"  
  implementor="#fyqqRespServiceImpl"
  address="/fyqqResp" ></jaxws:endpoint>


</beans>

接口:
@WebService
public interface IFyqqRespService {

public String getRespXML(@WebParam(name="cbr")int cbr) throws ParseException;
}

实现类:

@WebService(endpointInterface = "com.thunisoft.fy.gxpt.server.webservice.service.IFyqqRespService")
public class FyqqRespServiceImpl extends GXPTBaseService implements IFyqqRespService {

}

http://localhost:8888/FyServer/fyqqResp?wsdl 这样访问时,报404,控制台报
Can't find the request for http://localhost:8888/FyServer/fyqqResp's Observer;

http://localhost:8888/FyServer/这样访问时,报

No services have been found.

解决方案:

spring和struts的结合方式。
 两者的结合可以有以下三种方式:
 1.使用 spring 的 actionsupport 类整合 structs 
 2.使用 spring 的 delegatingrequestprocessor 覆盖 struts 的 requestprocessor 
 3.将 struts action 管理委托给 spring 框架 
 第1种方式用我们自己的action继承actionsupport。这种方式只是方便了我们在action中获得spring容器对象,在actionsupport中提供了getwebapplicationcontext()方法。获得了spring容器后,就可以享用spring容器中的bean了。
 第2种方式和第3种方式,都是把struts action 管理委托给 spring 框架 ,只是委托方式不一样。
 第2种方式使用 spring 的 delegatingrequestprocessor 覆盖 struts 的 requestprocessor。而delegatingrequestprocessor 所做的工作,也就是,获得spring容器,获得被spring容器管理的真正action。
 第3种方式在struts.xml中的action配置中配置:
  < action path=" /searchsubmit" type=" org.springframework.web.struts.delegatingactionproxy" > ...
 而这个代理action:delegatingactionproxy所做的工作也是,获得spring容器,获得被spring容器管理的真正action。
这3种结合方式,都需要获得spring容器:
 在这三种spring和struts的结合方式中都通过以下方式获得spring容器:
 delegatingactionutils.findrequiredwebapplicationcontext(actionservlet actionservlet moduleconfig moduleconfig)
 而这种方法会先去寻找以struts插件形式,创建的spring容器。也就是以上面spring加载方式3中的key值到servletcontext中找。
 如果找不到,再调用webapplicationcontextutils.getwebapplicationcontext(servletcontext context)方法获得spring容器。
结论:spring和struts的三种结合方式中,会先去寻找以struts插件形式,创建的spring容器。所以我们在struts中配置spring的加载插件,可以满足这三种结合方式。在找不到以struts插件形式,创建的spring容器后,会去找以contextloaderlistener或contextloaderservlet创建的spring容器,所以,不管以那种方式创建的spring容器都能满足spring和struts的三种结合方式。

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

的加载方式替换

 <servlet>
  <servlet-name>context</servlet-name>
  <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>

 

原帖地址:

http://topic.csdn.net/u/20110819/18/794715e3-51d2-4cc8-807b-460b461a4d82.html