Web服务 - 客户端类

时间:2010-06-06 07:54:20

标签: java web-services

我实现的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 {

有人可以请指出为什么会发生名称冲突以及我需要更改哪些注释?

感谢

2 个答案:

答案 0 :(得分:0)

我的老师建议(除其他原因外)我运行wsimport实用程序的方式可能有问题,所以我使用wsimport重新生成了客户端类文件,问题解决了。可能是因为我没有在开头指定包名,而是第一次手动完成,但我不确定。

答案 1 :(得分:0)

我得到了同样的例外。原因是这两个类的名称相似。当您在wsdl生成过程中拥有名为UserJoined的类时,JAXB会生成名为UserJoinedResponse的元素(请参阅您的wsdl文件)。

您尝试添加另一个具有相同名称的类(UserJoinedResponse)。因此,只需重命名UserJoinedResponse类或在异常中提及注释它。