Spring JAX-WS: ‘xxx’はインタフェースであり、JAXBはインタフェースを処理できません
問題
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でのインターフェイスのマッピング方法については、このhttp://jaxb.java.net/guide/Mapping__interfaces.html[非公式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メソッドを無視します。