2010-06-06 272 views
0

,我實行的是啓動和運行,當我嘗試運行客戶端,我得到以下錯誤關於使用的wsimport生成的類Web服務,Web服務 - 客戶端類

Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 4 counts of IllegalAnnotationExceptions 
Two classes have the same XML type name "{http://server.agency.hw2/}userJoined". Use @XmlType.name and @XmlType.namespace to assign different names to them. 
    this problem is related to the following location: 
     at hw2.chat.backend.main.generatedfromserver.UserJoined 
     at public javax.xml.bind.JAXBElement hw2.chat.backend.main.generatedfromserver.ObjectFactory.createUserJoined(hw2.chat.backend.main.generatedfromserver.UserJoined) 
     at hw2.chat.backend.main.generatedfromserver.ObjectFactory 
    this problem is related to the following location: 
     at ChatCompany.BackendChatServer.hw2.chat.backend.main.generatedfromserver.UserJoined 
Two classes have the same XML type name "{http://server.agency.hw2/}userJoinedResponse". Use @XmlType.name and @XmlType.namespace to assign different names to them. 
    this problem is related to the following location: 
     at hw2.chat.backend.main.generatedfromserver.UserJoinedResponse 
     at public javax.xml.bind.JAXBElement hw2.chat.backend.main.generatedfromserver.ObjectFactory.createUserJoinedResponse(hw2.chat.backend.main.generatedfromserver.UserJoinedResponse) 

但我無法弄清楚錯誤到底是什麼意思。我假設我需要改變的東西的註解在這些類由編譯器指出:

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "userJoinedResponse") 
public class UserJoinedResponse { 


} 


@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "userJoined", propOrder = { 
    "arg0" 
}) 
public class UserJoined { 

可能有人請指出爲什麼有一個名稱衝突,我需要改變什麼註解?

感謝

+0

所有生成的代碼是在'wsimport'的一次執行中產生的,還是多次執行的? – skaffman 2010-06-06 08:45:25

+0

錯誤,wsimport的執行次數是什麼意思?如果這回答我只是通過Windows CMD運行命令。 – Noona 2010-06-06 09:10:43

+0

您可以粘貼UserJoined類中使用的註釋嗎?你在處理你自己沒有寫的代碼嗎?如果是,請在所有代碼中搜索「name =」userJoinedResponse「」和「name =」userJoined「',看看是否找到重複的註釋。 – 2010-06-06 09:56:17

回答

0

我的老師曾建議(除其他原因外),也許有什麼毛病我跑的wsimport實用的方式,讓我再生利用的wsimport客戶端類文件,問題就解決了。可能是因爲我沒有在開始時指定軟件包名稱,並且第一次手動執行了它,但我不確定。

0

我得到了同樣的例外。原因是兩個類的名稱相似。當您在wsdl生成過程中使用名稱爲UserJoined的類時,JAXB會生成名稱爲UserJoinedResponse的元素(請參閱您的wsdl文件)。

而您嘗試添加另一個具有相同名稱的類(UserJoinedResponse)。所以只需重命名UserJoinedResponse類,或者按照例外中提到的註釋它。