您的位置:首页 > 其它

CXF实践中异常总结【记录收藏篇】

2015-02-09 14:14 531 查看
CXF发布WebService以及调用WebService,网上有很多实践的demo。但是根据网上的 demo不断实践,熟练掌握CXF的使用,以及总结开发CXF的异常。

CXF发布服务,有三种形式:根据main方法发布【Java Project项目】;不基于Spring方式发布到Web容器中,比如Tomcat容器【web项目】;基于Spring方式发布到Web容器中。【web项目】
因为CXF的特性之一,与Spring框架很好的集成。但是若是项目中不要求用Spring框架,但是又必须要求使用CXF框架呢?嘻嘻,所以,每个方式都需要掌握。
但是,既然每个框架都有自己的特性,所以应该扬长避短。

那我们总结一下,开发过程中,遇到的问题:
第一:若出现以下问题:

[html]
view plaincopyprint?

Exception in thread "main" java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;

at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:247)

at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)

at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:78)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:292)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)

at com.client.JaxWsDynamicClient.main(JaxWsDynamicClient.java:10 )

Exception in thread "main" java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:247)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:78)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:292)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
at com.client.JaxWsDynamicClient.main(JaxWsDynamicClient.java:10 )


[align=left]异常分析原因:[/align]
[align=left]jar包冲突问题;在tomcat下lib下有个wsdl-1.5.jar,而在cxf中则要使用的wsdl-1.6.jar。[/align]
[align=left]解决方案:[/align]
[align=left]把tomcat下的wsdl-1.5.jar去掉。【暂时为了此项目去掉】[/align]
[align=left]第二:若使用动态调用wsdl方式调用服务端时,出现以下异常:[/align]

[html]
view plaincopyprint?

Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException : Failed to create service.

at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:80)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:292)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)

at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)

at com.ws.client.ClientTest.main( ClientTest.java:28)

Caused by: javax.wsdl.WSDLException: WSDLException (at /soap:Envelope):
faultCode=INVALID_WSDL: Expected element '{http://schemas.xmlsoap.org/wsdl/}definitions'.

at com.ibm.wsdl.xml.WSDLReaderImpl.checkElementName(Unknown Source)

at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)

at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)

at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:247)

at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)

at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:78)

... 5 more

Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException : Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:80)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:292)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
at com.ws.client.ClientTest.main( ClientTest.java:28)
Caused by: javax.wsdl.WSDLException: WSDLException (at /soap:Envelope): faultCode=INVALID_WSDL: Expected element '{http://schemas.xmlsoap.org/wsdl/}definitions'.
at com.ibm.wsdl.xml.WSDLReaderImpl.checkElementName(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:247)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:78)
... 5 more


[align=left]异常分析原因:[/align]
[align=left]wsdl的问题。[/align]
[align=left]解决方案:注意wsdl后面必须添加上"?wsdl"[/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: