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

时间:2012-09-05 05:21:48

标签: java annotations jaxb

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

InfoSource

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

public class InfoSource {

    @XmlElement
    protected List<String> infoSource;

NameSearchFilters

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

})
public class NameSearchFilters {

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

SearchRequest

@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;

为什么这里有问题?

3 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:2)

这样的情况会引发异常'x count of IllegalAnnotationExceptions'

A级{} B级延伸A {}
C类延伸A {}

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

@XmlTransient
公共类A {}

答案 2 :(得分:0)

@XmlType(name =“Info_Source”,propOrder = {     “infoSource”

在代码中尝试此操作