问题
集成Spring + JAX-WS,请参见下面的Web服务:
package com.mkyong.user.ws;
//imports...
@WebService()
public class PGUserWS {
//DI via Spring
private UserBo userBo;
public UserBo getUserBo() {
return userBo;
}
public void setUserBo(UserBo userBo) {
this.userBo = userBo;
}
@WebMethod(operationName = "addUser")
public boolean addUser(@WebParam(name = "userId")
String userId, @WebParam(name = "User")
User user) throws SOAPException {
userBo.addUser(userId, user);
return true;
}
}
“ userBo ”是通过Spring XML bean配置的DI。 但是,当该服务(通过wsgen )生成该服务的文件以进行部署时,会出现“ JAXB无法处理接口 ”错误消息,请参见以下内容:
Caused by: java.security.PrivilegedActionException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:
2 counts of IllegalAnnotationExceptions
com.mkyong.user.bo.UserBo is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at com.mkyong.user.bo.UserBo
at private com.mkyong.user.bo.UserBo com.mkyong.user.ws.jaxws.SetUserBo.arg0
at com.mkyonguser.ws.jaxws.SetUserBo
com.mkyong.user.bo.UserBo does not have a no-arg default constructor.
this problem is related to the following location:
at com.mkyong.user.bo.UserBo
at private com.mkyong.user.bo.UserBo com.mkyong.user.ws.jaxws.SetUserBo.arg0
at com.mkyong.user.ws.jaxws.SetUserBo
解
请参阅此非官方的JAXB指南,以了解如何在JAXB中映射接口。
但是,您的情况有所不同,为“ userBo ”生成Web服务方法只是没有意义,仅通过Spring要求Di,而不发布给客户端。
要停止“ wsgen ”生成“ userBo ”的Web方法,只需使用“ @WebMethod(exclude = true)
”对其进行注释,请参见下文:
package com.mkyong.user.ws;
//imports...
@WebService()
public class PGUserWS {
private UserBo userBo;
@WebMethod(exclude = true)
public UserBo getUserBo() {
return userBo;
}
@WebMethod(exclude = true)
public void setUserBo(UserBo userBo) {
this.userBo = userBo;
}
@WebMethod(operationName = "addUser")
public boolean addUser(@WebParam(name = "userId")
String userId, @WebParam(name = "User")
User user) throws SOAPException {
userBo.addUser(userId, user);
return true;
}
}
现在,“ wsgen ”将忽略“ userBo ”的getter和setter方法。