IllegalAnnotationsException:Class有两个同名的属性

我正在尝试使用RSA 7.5和Websphere 7服务器开发IBM JAX_WS Web服务。 由于我是初学者,因此我遵循Java级第一种方法,即我首先创建Java类,然后生成WSDL文件。

当我尝试创建wsdl文件时,我得到一个例外:

java.security.PrivilegedActionException:com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationsException的1个计数Class有两个同名的属性“planId”

我的class级在这里看起来像这样:

public class MemberDetails{ @XMLElement(required=true) private String planId; //public getters and setters for the planId; } 

我不知道为什么会发生这种exception。 通过谷歌搜索,我尝试了一些替代方案来解决它,但没有一个为我工作:(

注意:

这是我在整个工作区中使用的唯一注释。 我不确定这是否依赖于其他一些注释。 但我尝试了一些诸如@XMLElement(name =“Plan”,required = true),@ XMLType等,但每次我都得到这个例外。

这个例外是在wsgen期间发生的。 ( java.lang.reflect.InvocationTargetException

编辑

基本上,当我们从java服务方法创建一个wsdl并在SOAP UI中打开该WSDL时,我们在每个元素的顶部都得到 。 我想删除这个选项标签标签,因此我尝试使用@XMLElement(required = true)方法,这样当我在SOAP UI中打开WSDL时, 不会似乎是强迫因素。

根据我的概念,@ XMLElement(required = true)将minOccurs设置为1,即大于零,因此当我在SOAP UI中打开它时,可选的注释将从WSDL中删除。 但不幸的是它不起作用因此我的概念不正确。 生成WSDL之后,我可以看到minOccurs仍为0。

请解释在SOAP UI中打开WSDL时如何删除可选标记。

问候,

默认情况下, JAXB(JSR-222)实现处理公共访问器方法和带注释的字段。 如果您注释一个您也有get / set方法的字段,则会出现以下exception:

如果要注释字段,则应指定@XmlAccessorType(XmlAccessType.FIELD)

 @XmlAccessorType(XmlAccessType.FIELD) public class MemberDetails{ @XMLElement(required=true) private String planId; //public getters and setters for the planId; } 

或者您可以注释该属性

 public class MemberDetails{ private String planId; @XMLElement(required=true) public String getPlanId() { return planId; } } 

了解更多信息

对于@XmlTransient在getter或setter上使用@XmlTransient进行批注可以防止冲突。

在此处查看更多信息: http : //docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/XmlTransient.html