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

Java 两个类具有相同的XML类型名称,java,annotations,jaxb,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://te

我有一个错误,它说我有两个相同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 = "", 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”)

@XmlType(name=“Info_Source”,propOrder={ “信息源”


在类似这样的情况下,在代码中尝试此操作会引发异常“x个IllegalAnnotationExceptions计数”

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

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

@xmltransive

公共类A
{}

在上下文创建过程中,您的代码什么时候会失败?它在我的框中不会失败,但我没有可用的类名SearchCriteria。也许您也可以发布它?应用程序跨多个TEIR工作,未部署时工作正常,问题是部署到服务器时(本例中为本地tomcat)当我的marshaller被调用时。明白吗,你在系统上运行不同的JDK/JRE吗?我可能是JAXB版本造成了麻烦…我确信我在系统上只有一个JDK和JRE。我已经尝试了这个方法,它修复了一个c=count的问题,在InfoSource中将名称更改为命名空间修复了它的问题,它没有修复问题的最后计数。这是e吗nd up解决了命名空间更改在整个项目中反映的问题(XML方案)
@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;