Cxf开发webservice时遇到Can't find the request for xx's Observer

fanyuna 2011-08-19 06:59:16
最近在用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.

希望高手们帮帮忙吧!我刚开始以为是JAR 包的问题,一朋友帮做了个例子,可以正常访问。然后我把我系统里的JAR包全拷到那个例子里面还是可以正常访问,但我把例子里的JAR包拷到我的项目里面仍然是同样的错儿。由于我们的web.xml配了一些listener,而且url-pattern全是/*,朋友猜可能是这个的问题,但我把配置注释了还是同样的错误。
...全文
3455 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
liudonghai@360buy.com哥发我一下,我也研究研究
crossdqw 2011-12-17
  • 打赏
  • 举报
回复
你在客户端删掉web.xml中的cxf配置或者是在mapping中不要让它映射所有<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/加上路径/*</url-pattern>
</servlet-mapping>
不然就会首先映射CXFServlet,就会找不到服务!
qiuzhenguang 2011-11-28
  • 打赏
  • 举报
回复
我也是遇到这个问题警告: Can't find the request for http://localhost:8080/myCXFtest/one/myservice/uris's Observer

楼主,发个demo给我吧。etherpulong@gmail.com
fixed 2011-11-21
  • 打赏
  • 举报
回复
楼主 求 demo !!!!
邮箱 fixed_2008@126.com
acdy 2011-09-07
  • 打赏
  • 举报
回复
楼主,可以把你的小demo发给我一个不,我的邮箱是wodettianxia@163.com,谢谢
fanyuna 2011-08-31
  • 打赏
  • 举报
回复
是JAR包的问题,人的第一直觉大多数是对的
fanyuna 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 a372048518 的回复:]
只需修改spring和struts结合的方式,不用修改项目源码;
[/Quote]

嗯,谢谢!服务端的问题解决了,是换了Spring的加载方式,用contextloaderlistener这种方式是可行的,pulg-in这种方式不知道为什么不行,需要高手来解释下或有时间再看下CXF的源码。

现在我在客户端调用时又出现问题了


JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(IFyqqRespService.class);
factory.setAddress(endPoint);
(IFyqqRespService) factory.create();
我以这种方式调用的,一运行到最后一句时就报

警告: Initial attempt to crate application context was unsuccessful.
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [META-INF/cxf/cxf.xml]; nested exception is java.lang.IllegalAccessError: tried to access method com.ctc.wstx.stax.WstxInputFactory.createPrivateConfig()Lcom/ctc/wstx/api/ReaderConfig; from class com.ctc.wstx.sax.WstxSAXParser
Caused by: java.lang.IllegalAccessError: tried to access method com.ctc.wstx.stax.WstxInputFactory.createPrivateConfig()Lcom/ctc/wstx/api/ReaderConfig; from class com.ctc.wstx.sax.WstxSAXParser
at com.ctc.wstx.sax.WstxSAXParser.<init>(WstxSAXParser.java:128)
at com.ctc.wstx.sax.WstxSAXParserFactory.newSAXParser(WstxSAXParserFactory.java:105)
at org.apache.cxf.bus.spring.TunedDocumentLoader.loadDocument(TunedDocumentLoader.java:107)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:405)
at org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader.doLoadBeanDefinitions(ControlledValidationXmlBeanDefinitionReader.java:109)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:357)
at org.apache.cxf.bus.spring.ControlledValidationXmlBeanDefinitionReader.loadBeanDefinitions(ControlledValidationXmlBeanDefinitionReader.java:131)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:109)
at org.apache.cxf.bus.spring.BusApplicationContext.loadBeanDefinitions(BusApplicationContext.java:262)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:294)
at org.apache.cxf.bus.spring.BusApplicationContext.<init>(BusApplicationContext.java:91)
at org.apache.cxf.bus.spring.SpringBusFactory.createApplicationContext(SpringBusFactory.java:102)
at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:93)
at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:86)
at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:64)
at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:53)
at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:69)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:106)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:97)
at org.apache.cxf.endpoint.AbstractEndpointFactory.getBus(AbstractEndpointFactory.java:73)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.initializeServiceFactory(AbstractWSDLBasedEndpointFactory.java:228)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:99)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:51)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:102)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:115)
at com.thunisoft.fy.ws.FyqqRespClient.getMessageService(FyqqRespClient.java:44)
at com.thunisoft.fy.ws.FyqqRespClient.getInfo(FyqqRespClient.java:48)
at com.thunisoft.fy.pub.message.HintMsgLogic.showHintMsg(HintMsgLogic.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

不知道什么原因,是不是JAR包的问题啊?
magong 2011-08-20
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 fanyuna 的回复:]

由于我不能为了这个接口改之前项目的架构,望高手能给出解决这个问题的方案,谢谢了!
[/Quote]
你把struts-spring plugin拿掉,ContextLoaderListener加上试试看。
fanyuna 2011-08-20
  • 打赏
  • 举报
回复
我刚才把朋友给的例子中Spring的加载方式换成我们项目一样的,结果出现no services found访问不了的情况了,是不是CXF配置文件必须得用org.springframework.web.context.ContextLoaderListener这种加载方式 才可以?望高手指点

由于我不能为了这个接口改之前项目的架构,望高手能给出解决这个问题的方案,谢谢了!
a372048518 2011-08-20
  • 打赏
  • 举报
回复
只需修改spring和struts结合的方式,不用修改项目源码;
a372048518 2011-08-20
  • 打赏
  • 举报
回复
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的三种结合方式。
fanyuna 2011-08-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ticmy 的回复:]
哥恰好有一个cxf的小demo,给邮箱发给你
[/Quote]

谢谢哥们,我邮箱297971781@qq.com.
fanyuna 2011-08-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 magong 的回复:]

你这么说也没错,不过它只是获得,并不是初始化。
[/Quote]

请教下,应该如何初始化啊?我曾在web.xml中这样配置过:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>CXF的配置文件</param-value>
</context-param>

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

这样估计跟我们加载Spring的方式 有冲突吧,报错儿。
龙四 2011-08-20
  • 打赏
  • 举报
回复
哥恰好有一个cxf的小demo,给邮箱发给你
magong 2011-08-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fanyuna 的回复:]

这个代理action:DelegatingActionProxy所做的工作也是,获得spring容器,获得被spring容器管理的真正action。
[/Quote]
你这么说也没错,不过它只是获得,并不是初始化。
fanyuna 2011-08-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 magong 的回复:]
哦,楼主不会忘了配置Spring吧

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

我们项目中Spring加载方式:

在struts.xml中的action配置中配置:
<action path="/test" type="org.springframework.web.struts.DelegatingActionProxy"> 而这个代理action:DelegatingActionProxy所做的工作也是,获得spring容器,获得被spring容器管理的真正action。

我以同样的方式加载的CXF配置文件
magong 2011-08-19
  • 打赏
  • 举报
回复
哦,楼主不会忘了配置Spring吧

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
magong 2011-08-19
  • 打赏
  • 举报
回复
贴出来的这些确实没发现问题。
可能楼主要多帖点东西了。
fanyuna 2011-08-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 heiboyyang 的回复:]
路径问题错误
看看你的配置文件不是什么其它的错误就是报找不到相应的服务和页面
[/Quote]

这个路径不就看两个地方吗?一个是<url-pattern>/services/*</url-pattern>,一个是address="/fyqqResp"吧?这样路径就是http://localhost:端口/工程名/services/fyqqResp?wsdl吗?
HeiBoyYang 2011-08-19
  • 打赏
  • 举报
回复
路径问题错误
看看你的配置文件不是什么其它的错误就是报找不到相应的服务和页面

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧