IllegalAnnotationsException:类有两个同名的属性 [英] IllegalAnnotationsException: Class has two properties of same name

查看:100
本文介绍了IllegalAnnotationsException:类有两个同名的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to develop a IBM JAX_WS web service using RSA 7.5 and Websphere 7 server. Since I am a beginner, hence I am following Java-class first approach i.e. I am creating the Java classes first and then generating the WSDL file.

当我尝试创建 wsdl 文件时,出现异常:

When i try to create the wsdl file, i am getting an exception:

java.security.PrivilegedActionException:com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 个 IllegalAnnotationsException类有两个同名的属性planId"

我在这里引用的类看起来像这样:

My class refered here looks something like this:

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

我不知道为什么会发生这种异常.通过谷歌搜索,我尝试了一些替代方法来解决它,但没有一个对我有用:(

I dont have any idea like why is this exception happening. Via Google search I tried a few alternatives to resolve it but none of them worked for me :(

注意:

这是我在整个工作区中使用的唯一注释.我不确定这是否依赖于其他一些注释.但是我尝试了一些,例如@XMLElement(name="Plan",required=true)、@XMLType 等,但每次我都遇到此异常.

This is the only annotation I am using throughout my workspace. I am not sure if this is dependent on some other annotations or not. But I tried with a few such as @XMLElement(name="Plan",required=true), @XMLType, etc but every time I am getting this exception.

此异常发生在 wsgen 期间.(java.lang.reflect.InvocationTargetException)

This exception is occuring during wsgen. (java.lang.reflect.InvocationTargetException)

编辑

基本上,当我们从 java 服务方法创建 wsdl 并在 SOAP UI 中打开该 WSDL 时,我们会在每个元素的顶部得到 <!--Optional-->.我想删除此选项标记 <!--Optional--> 标记,因此我正在尝试使用 @XMLElement(required=true) 方法,以便当我在 SOAP UI 中打开 WSDL <!--Optional--> 不会出现在强制元素中.

Basically, when we create a wsdl from java service method and open that WSDL in SOAP UI, then we get <!--Optional--> at the top of every element. I want to remove this option tag <!--Optional--> tag, hence I am trying for @XMLElement(required=true) approach so that when I open the WSDL in SOAP UI <!--Optional--> does not appears for compulsary elements.

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

According to my concept, @XMLElement(required=true) will set the minOccurs to 1 i.e. greater than zero and hence the optional comment will be removed from WSDL when I open it in SOAP UI. But Unfortunately its not working hence my concept is incorrect. After the WSDL is generated, I can see that the minOccurs is still 0.

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

Please explain how can I remove the optional tag when I open the WSDL in SOAP UI.

问候,

推荐答案

默认 JAXB (JSR-222) 实现处理公共访问器方法和带注释的字段.如果你注释一个你也有 get/set 方法的字段,你会得到这个异常:

By default JAXB (JSR-222) implementations process public accessor methods and annotated fields. If you annotate a field that you also have get/set methods for you will get this exception:

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

If you are going to annotate fields then you should specify @XmlAccessorType(XmlAccessType.FIELD)

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

或者你可以对属性进行注释

Or you can annotate the property

public class MemberDetails{

    private String planId;

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

了解更多信息

这篇关于IllegalAnnotationsException:类有两个同名的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆