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指南,以了解如何在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方法。

翻译自: https://mkyong.com/webservices/jax-ws/spring-jax-ws-xxx-is-an-interface-and-jaxb-cant-handle-interfaces/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值