2012-09-05 71 views
1

林有這個錯誤,它說,我有兩個類相同的XML類型名稱的兩類具有相同的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; 

爲什麼會出現問題嗎?

+0

什麼時候你的代碼失敗,上下文創建期間?它不會在我的盒子上失敗,但我沒有可用的NameSearchCriteria類。也許你可以發佈這個呢? – home

+0

該應用程序可以跨多個teirs工作,並且在未部署時可以正常工作,問題是在調用marshaller時部署到服務器(本例中爲本地tomcat)時的問題。 –

+0

瞭解,您是否在系統上運行不同的JDK/JRE?我可能是JAXB版本造成麻煩... – home

回答

5

您是否嘗試給它們中的每一個添加名稱空間屬性的不同值,如@XmlType(namespace="test1", name = "InfoSource", propOrder = { "infoSource" }))

+0

我試過這個問題修復了一個問題的c = ount,在InfoSource中將名稱更改爲名稱空間修復了它的問題,但並未修復問題的最後一個計數。 –

+0

這確實最終解決了在項目中反映名稱空間更改時的問題(XML方案) –

0

@XmlType(NAME = 「Info_Source」,propOrder = { 「infoSource」

試試這個代碼

+0

是完整的代碼嗎? –

2

像這樣的情況引發異常

A級 'X IllegalAnnotationExceptions計數'{ }
B類延伸的{}
C類延伸的{}

解決問題加入阿魯塔季翁爲A級是這樣的:

@XmlTransient
公共類A
{}

相關問題