Spring WebSerivce

 

java.lang.IllegalStateException: No adapter for endpoint [public com.mycompany.hr.entity.HolidayResponse com.mycompany.hr.ws.HolidayEndpoint.handleHolidayRequest(org.jdom2.Element) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?

at org.springframework.ws.server.MessageDispatcher.getEndpointAdapter(MessageDispatcher.java:289)

at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:230)。。。

 

用spring webservice 官方文档做Demo时,报了这个异常,找了一天一夜,发现是自己的问题,

 

官方例子中提供的 HolidayEndpoint 类中有一个方法

 

 

 @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")

    public HolidayResponse handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {

    HolidayResponse re = new HolidayResponse();

        Date startDate = parseDate(startDateExpression, holidayRequest);

        Date endDate = parseDate(endDateExpression, holidayRequest);

        String name = firstNameExpression.evaluateFirst(holidayRequest).getText() + " " + lastNameExpression.evaluateFirst(holidayRequest).getText();

 

        humanResourceService.bookHoliday(startDate, endDate, name);

        return re;

    }

 

我自己写的测试类如下

 

public static void main(String args[]) {

try {

// WebService所在的URL

HumanResourceService s = new HumanResourceService();

HumanResource resource = s.getHumanResourceSoap11();

HolidayRequest holidayRequest = new HolidayRequest();

holidayRequest.setDatas(9);

resource.holiday(holidayRequest);

} catch (Exception e) {

e.printStackTrace();

}

}

 

发生异常的原因:我在调用webservice 接口是传入的类型跟 handleHolidayRequest 中参数的类型不一样

解决方案:传入参数时传入Elements 类型的参数 或者把handleHolidayRequest  中Element参数改成你自己的定义的request 类型。

 

希望对大家有所帮助,谢谢!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值