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

来源:互联网 发布:淘宝的退款率怎么看 编辑:程序博客网 时间:2024/06/07 07:23
记录下!!,今天webService 生成客户端 运行报错 Use @XmlType.name and @XmlType.namespace to assign different names to them. 
错误如下:
Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContextat 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 IllegalAnnotationExceptionsTwo 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.SayResponseat 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.ObjectFactorythis problem is related to the following location:at com.bqjr.storesys.base.entity.SayResponseat java.security.AccessController.doPrivileged(Native Method)at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:143)... 10 moreCaused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptionsTwo 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.SayResponseat 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.ObjectFactorythis problem is related to the following location:at com.bqjr.storesys.base.entity.SayResponseat 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 0
原创粉丝点击