簡體   English   中英

Web服務-客戶端類

[英]web service - client classes

我實施的Web服務已啟動並正在運行,當我嘗試運行客戶端時,對於使用wsimport生成的類,我收到以下錯誤消息,

    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 {

有人可以指出為什么會有名稱沖突以及我需要更改哪些注釋嗎?

謝謝

我的老師建議(除其他原因外),也許我運行wsimport實用程序的方式出了問題,因此我使用wsimport重新生成了客戶端類文件,問題得以解決。 可能是因為我一開始沒有指定軟件包名稱,而是第一次手動進行了命名,但是我不確定。

我有同樣的例外。 原因是兩個類的名稱相似。 在wsdl生成過程中擁有名稱為UserJoined類時,JAXB會生成名稱為UserJoinedResponse元素(請參見wsdl文件)。

然后,您嘗試添加具有相同名稱的另一個類( UserJoinedResponse )。 因此,只需重命名UserJoinedResponse類或按照異常中的說明對其進行注釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM