繁体   English   中英

两个类具有相同的 XML 类型名称

[英]Two Classes have same XML type name

我有这个错误,它说我有两个相同的 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;

为什么这里有问题?

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

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

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

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

@XmlTransient
公开课A
{}

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

在代码中试试这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM