情景描述:在我的webservice服务中,要调用远程写好的一个服务;由于我的后台是用CXF方式开发的,所以调用远程的方式采用的是由wsdl生成本地代理接口来实现的,生成本地接口的代码如下:
F:\jar包驱动\apache-cxf-2.6.0\bin>wsdl2java -p com.dyc.client -d d:/ws -verbose http://localhost:7000/gisplatform/SpatialAnalysisService?wsdl
然后将生成的在ws目录下的源文件COPY到我的工程中调用,报下面错误
信息: Creating Service {http://www.sgcc.com.cn/sggis/service/gisservice}SpatialAnalysisServiceService from class cn.creaway.webgis.proxy.SpatialAnalysisService
Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:297)
at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:474)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:685)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:536)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:248)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:205)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:90)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:155)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:156)
at cn.creaway.webgis.business.SpatialAnalysisServiceBusiness.computeUserLineLengthStatisticByDept(SpatialAnalysisServiceBusiness.java:71)
at cn.creaway.webgis.business.SpatialAnalysisServiceBusiness.main(SpatialAnalysisServiceBusiness.java:85)
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
两个类具有相同的 XML 类型名称 "{http://www.sgcc.com.cn/sggis/service/gisservice}computePSRStatisticByDept"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。
this problem is related to the following location:
at cn.creaway.webgis.proxy.jaxws_asm.ComputePSRStatisticByDept
this problem is related to the following location:
at cn.creaway.webgis.proxy.ComputePSRStatisticByDept
at public cn.creaway.webgis.proxy.ComputePSRStatisticByDept cn.creaway.webgis.proxy.ObjectFactory.createComputePSRStatisticByDept()
at cn.creaway.webgis.proxy.ObjectFactory
两个类具有相同的 XML 类型名称 "{http://www.sgcc.com.cn/sggis/service/gisservice}computeLineLengthStatisticByDeptResponse"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。
this problem is related to the following location:
at cn.creaway.webgis.proxy.jaxws_asm.ComputeLineLengthStatisticByDeptResponse
this problem is related to the following location:
at cn.creaway.webgis.proxy.ComputeLineLengthStatisticByDeptResponse
at public cn.creaway.webgis.proxy.ComputeLineLengthStatisticByDeptResponse cn.creaway.webgis.proxy.ObjectFactory.createComputeLineLengthStatisticByDeptResponse()
at cn.creaway.webgis.proxy.ObjectFactory
两个类具有相同的 XML 类型名称 "{http://www.sgcc.com.cn/sggis/service/gisservice}computePSRStatisticByDeptResponse"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。
this problem is related to the following location:
at cn.creaway.webgis.proxy.jaxws_asm.ComputePSRStatisticByDeptResponse
this problem is related to the following location:
at cn.creaway.webgis.proxy.ComputePSRStatisticByDeptResponse
at public cn.creaway.webgis.proxy.ComputePSRStatisticByDeptResponse cn.creaway.webgis.proxy.ObjectFactory.createComputePSRStatisticByDeptResponse()
at cn.creaway.webgis.proxy.ObjectFactory
.......................................
开始一直怀疑是因为我项目中的服务名与我调用的服务名之间有冲突,根据异常信息很容易让人如此思考;后来无意中打开一个接口文发现,原理我COPY到工程中时,包的路径改变了,而原接口引用的类路径却还是我生成时用的目录,如下:
......................................................
@ResponseWrapper(localName = "computePSRStatisticByDeptResponse", targetNamespace = "http://www.sgcc.com.cn/sggis/service/gisservice", className = "com.dyc.client.ComputePSRStatisticByDeptResponse")
public java.lang.String computePSRStatisticByDept(
@WebParam(name = "InputXML", targetNamespace = "") java.lang.String inputXML);
.......................................................
可以发现我的className一直引用的是我原来的包名,而我现在的包名是cn.gary.test
修改方法,改接口显然不实际,所以重新生成接口,修改命令为:
F:\jar包驱动\apache-cxf-2.6.0\bin>wsdl2java -p cn.gary.test -d d:/ws -verbose http://localhost:7000/gisplatform/SpatialAnalysisService?wsdl
再将生成的接口COPY到相同的接口下,就不会再报错了。
总结:同样的异常也有可能别的原因引起的,这里只是其中一种可能.
分享到:
相关推荐
利用Apache CXF开发webservice接口需要用到的jar集合 cxf-core-3.0.15.jar cxf-rt-bindings-soap-3.0.15.jar cxf-rt-bindings-xml-3.0.15.jar cxf-rt-databinding-jaxb-3.0.15.jar cxf-rt-frontend-jaxws-3.0.15.jar...
<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"/>
apache-cxf-2.6.2.tar.gz CXF及其依赖包
webservice CXF 报错:java.lang.NoClassDefFoundError: org/apache/neethi/builders/AssertionBuilder 需要用到此jar文件 通过apache官网可获得。 文件位置\apache-cxf-2.7.13\lib
cxf-2.1.jar cxf-2.1.jar cxf-2.1.jar cxf-2.1.jar
cxf-core-3.1.16版本jar包,用于java开发使用
apache-cxf-3.3.5版本.rar
apache-cxf-2.6.0.tar.gz
apache-cxf-3.1.18版本.rar
Java通过Cxf创建webService接口.docxJava通过Cxf创建webService接口.docx
基于CXF实现WebService开发.pdf
apache-cxf-2.7.6.rar webservice
cxf+参考文档.pptcxf+参考文档.ppt
Apache CXF Web Service Development.pdf
cxf框架包.zip
apache-cxf-2.4.6.zip
cxf-2.7.18. jar及其依赖包,可解决客户端调用提示source 1.5已过时问题。
CXF框架webservice教程.pdf
webservice cxf 简单加法 Eclipse.doc