今天使用myeclipse生成webservice时,一直报错:
An internal error occurred during: “Generating JAX-WS Web Services”.
Unable to create JAXBContext
在启动tomcat时显示如下错误:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name “debtAgeAnalysis”. Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at com.asiainfo.cbss.controller.jaxws.DebtAgeAnalysis
this problem is related to the following location:
at com.asiainfo.cbss.entity.DebtAgeAnalysis
at private java.util.List com.asiainfo.cbss.controller.jaxws.DebtAgeAnalysisResponse._return
at com.asiainfo.cbss.controller.jaxws.DebtAgeAnalysisResponse
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:447)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:288)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1111)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:106)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:153)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:149)
... 23 more
在controller的代码如下
@RequestMapping(value = "/debtAgeAnalysis" , consumes = "application/json")
@ResponseBody
public List<DebtAgeAnalysis> debtAgeAnalysis(
@RequestParam("stat_month") String stat_month,
@RequestParam("province_code") String province_code,
@RequestParam("eparchy_code") String eparchy_code,
@RequestParam("city_code") String city_code,
@RequestParam("net_type_code") String net_type_code) {
。。。。
}
经过仔细检查后发现,在webroot/WEB-INF/wsdl下的QueryControllerService_schema1.xsd文件中
webservice在自动生成时会根据对应的
DebtAgeAnalysis实体和debtAgeAnalysis方法生成对应的代码
由于DebtAgeAnalysis和debtAgeAnalysis两个名称相同,在生成代码时都会起名name=”debtAgeAnalysis”,由于两个名称相同,无法生成,故报错
只需修改debtAgeAnalysis方法的名称即可