【发布时间】:2014-08-13 13:05:59
【问题描述】:
我在生成 WSDL 时遇到问题。我想创建生成 json 字符串 的 SOAP Web 服务。下面的 pojo 类是从另一个 Web 项目引用到我的 Web 服务项目中的。我在 servlet response 对象上编写生成的 json 字符串,该对象是使用 WebServiceContext 创建的,并使用 @Resource 注释进行注释。
我也尝试调试 web 服务方法(用@WebParam 注释的参数化),pojo 但项目没有在调试模式下启动。在调用 web 方法之前,它为所有字段抛出异常:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 15 counts of IllegalAnnotationExceptions
Class has two properties of the same name "result"
this problem is related to the following location:
at public portal.common.ejb.LoginResult portal.common.ejb.LoginResponse.getResult()
at portal.common.ejb.LoginResponse
this problem is related to the following location:
at private portal.common.ejb.LoginResult portal.common.ejb.LoginResponse.result
at portal.common.ejb.LoginResponse
Class has two properties of the same name "userInfo"
this problem is related to the following location:
at public portal.common.ejb.UserDTO portal.common.ejb.LoginResponse.getUserInfo()
at portal.common.ejb.LoginResponse
this problem is related to the following location:
at private portal.common.ejb.UserDTO portal.common.ejb.LoginResponse.userInfo
at portal.common.ejb.LoginResponse
Class has two properties of the same name "notifications"
this problem is related to the following location:
at public java.util.List portal.common.ejb.LoginResult.getNotifications()
at portal.common.ejb.LoginResult
at private portal.common.ejb.LoginResult portal.common.ejb.LoginResponse.result
at portal.common.ejb.LoginResponse
this problem is related to the following location:
at private java.util.List portal.common.ejb.LoginResult.notifications
at portal.common.ejb.LoginResult
...
我正在使用 jaxws-ri-2.2.8、jaxws-json-1.2、jaxws-spring-1.9、 xbean-spring-3.9 & spring-framework-4.0.3.RELEASE-dist.
注意:我对网络服务不太熟悉,所以请保持礼貌和耐心。
POJO
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class LoginResponse {
private LoginResult result;
private UserDTO userInfo;
// Getter/setter
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class LoginResult {
private List<String> notifications;
private boolean success;
// Getter/setter
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class UserDTO {
private String eMail;
private Integer externalIdentifier;
private String firstName;
private String lastLoggedIn;
private String lastName;
private String phone;
private Integer role;
private String status;
private String title;
private int userId;
private String userIdentifier;
// Getter/setter
}
参考文档:
我也参考下面的链接来解决错误
JAXB's @XmlAccessorType - @Blaise Doughan
Jaxb, Class has two properties of the same name - Stackoverflow
IllegalAnnotationsException: Class has two properties of same name - Stackoverflow 等
我尝试了@Blaise Doughan 给出的所有示例。在 Java 应用程序和 Web 应用程序中也一切正常。还尝试生成 wsdl 并在控制台上生成并打印输出 xml。
谁能指出我的 pojo 课程有什么问题?我在这上面花了很多时间,但没有运气。我应该怎么做才能摆脱这个错误?
编辑:
我还尝试了在 getter 方法上的 @XmlTransient 注释和在所有字段上的 @XmlElement 注释,但同样的问题。
非常感谢
【问题讨论】:
-
如果注释 XmlAccessorType(XmlAccessType.FIELD) 怎么办?
-
注释 XmlAccessorType 注释时出现同样的问题。
标签: java spring web-services jaxb