5

我有这个错误,它说我有两个具有相同 XML 类型名称的类

所以问题在于 InfoSource -> NameSearchFilters -> SearchRequest

错误

Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://test.au/schema/namesearch}InfoSource". Use @XmlType.name and @XmlType.namespace to assign different names to them.
    this problem is related to the following location:
        at au.test.identitySearch.model.InfoSource
        at protected au.test.identitySearch.model.InfoSource au.test.identitySearch.model.nameSearch.NameSearchFilters.infoSourceList
        at au.test.identitySearch.model.nameSearch.NameSearchFilters
    this problem is related to the following location:
        at au.test.identitySearch.model.InfoSource
        at protected au.test.identitySearch.model.InfoSource au.test.identitySearch.model.nameSearch.NameSearchFilters.infoSourceList
        at au.test.identitySearch.model.nameSearch.NameSearchFilters
        at protected au.test.identitySearch.model.nameSearch.NameSearchFilters au.test.identitySearch.ws.model.SearchRequest.searchFilters
        at au.test.identitySearch.ws.model.SearchRequest

信息源

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InfoSource", propOrder = {
    "infoSource"
})

public class InfoSource {

    @XmlElement
    protected List<String> infoSource;

名称搜索过滤器

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "NameSearchFilters", propOrder = {

})
public class NameSearchFilters {

    @XmlElement
    protected InfoSource infoSourceList;
    @XmlElement
    protected String nameType;

搜索请求

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "searchControls",
    "searchCriteria",
    "searchFilters"
})
@XmlRootElement(name = "searchRequest")
public class SearchRequest {

    @XmlElement(required = true)
    protected SearchControls searchControls;
    @XmlElement(required = true)
    protected NameSearchCriteria searchCriteria;
    @XmlElement
    protected NameSearchFilters searchFilters;

为什么这里有问题?

4

3 回答 3

9

您是否尝试向它们中的每一个添加不同的命名空间属性值@XmlType(namespace="test1", name = "InfoSource", propOrder = { "infoSource" }) )

于 2012-09-05T06:48:04.000 回答
2

像这样的情况抛出异常'x counts of IllegalAnnotationExceptions'

类 A{}
类 B 扩展 A{}
类 C 扩展 A{}

解决向 A 类添加注释的问题,如下所示:

@XmlTransient
公共类 A
{}

于 2013-03-05T13:47:38.213 回答
-1

@XmlType(name = "Info_Source", propOrder = { "infoSource"

在代码中试试这个

于 2013-01-23T09:53:42.793 回答