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 类型。

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

猜你喜欢

转载自jiangwubo.iteye.com/blog/1561583
今日推荐