web service错误Use @XmlType.name and @XmlType.namespace to assign different names to them.

记录下!!,今天webService 生成客户端 运行报错 Use @XmlType.name and @XmlType.namespace to assign different names to them. 
错误如下:
Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext
	at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:156)
	at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:84)
	at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:235)
	at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:672)
	at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:660)
	at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:329)
	at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:312)
	at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:294)
	at javax.xml.ws.Service.getPort(Service.java:119)
	at com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.TestWebServicesService.getTestWebServicesPort(TestWebServicesService.java:72)
	at com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.test.main(test.java:6)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://entity.base.storesys.bqjr.com/}sayResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
	this problem is related to the following location:
		at com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.SayResponse
		at public com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.SayResponse com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.ObjectFactory.createSayResponse()
		at com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.ObjectFactory
	this problem is related to the following location:
		at com.bqjr.storesys.base.entity.SayResponse


	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:143)
	... 10 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://entity.base.storesys.bqjr.com/}sayResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them.
	this problem is related to the following location:
		at com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.SayResponse
		at public com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.SayResponse com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.ObjectFactory.createSayResponse()
		at com.bqjr.storesys.base.vo.com.bqjr.storesys.base.entity.ObjectFactory
	this problem is related to the following location:
		at com.bqjr.storesys.base.entity.SayResponse


	at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
	at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:451)
	at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:283)
	at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:126)
	at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1148)
	at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:173)
	at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:96)
	at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:98)
	at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:151)
	at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:143)
	... 12 more

代码如下


@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
@XMLType(name="CreateProcessResponse", namespace="http://xxx.yyy.com/message")
  •  给方法上加上下面的注解

@WebMethod(operationName="differentFromMethodName")

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值