加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Two classes have the same XML type name 排错

发布时间:2020-12-15 23:35:43 所属栏目:百科 来源:网络整理
导读:今天遇到一个问题,webservice发布的时候报下面的错误: Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptionsTwo classes have the same XML type name "{http://xxx.yyyy.com}createProcessRespo

今天遇到一个问题,webservice发布的时候报下面的错误:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://xxx.yyyy.com}createProcessResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
	this problem is related to the following location:
		at xxx.yyy.gwfp.ws.dto.CreateProcessResponse
		at private xxx.yyy.gwfp.ws.dto.CreateProcessResponse xxx.yyy.gwfp.ws.jaxws_asm.CreateProcessResponse._return
		at xxx.yyy.gwfp.ws.jaxws_asm.CreateProcessResponse
	this problem is related to the following location:
		at xxx.yyy.gwfp.ws.jaxws_asm.CreateProcessResponse

	at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
	at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
	at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
	at org.apache.cxf.jaxb.JAXBDataBinding.createContext(JAXBDataBinding.java:562)
	at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:502)
	at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:322)

代码如下:

@Stateless
@WebService()
public class AccountWS {

@WebMethod()
public CreateProcessResponse createProcess(@WebParam(name = "request") CreateProcessRequest request) {
    return null;
}

起初找不出来原因,后来才发现,由于JAX-WS对webservice里面得每个方法都生成一个类,生成的类名为:methodName+"Response",所以就回导致生成的类和原来的类有两个相同的xml type。

知道原因后,除了我们修改方法名外,还有下面的3种解决方法:

  • 更换返回值对象的name
@XMLType(name="CreateProcessResponseMsg", namespace"http://xxx.yyy.com")
  • 更换返回值对象的namespace
"CreateProcessResponse""http://xxx.yyy.com/message")
  • 给方法上加上下面的注解

@WebMethod(operationName="differentFromMethodName")

其实在最开始的时候说生成的class的名称是方法名+Response,是不准确的,operationName的默认值就是方法名,其实就是operationName+Response,这个注解其实会改变生成的类的名称,对接口是没有影响的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读