小编use*_*163的帖子

异步REST客户端

如何编写异步休息客户端?我的控制器(不确定它是不是因为异步).

@RequestMapping(method = RequestMethod.GET, value = "/get/all")
@ResponseBody
public Callable < CustomersListDTO > getAllCustomers() {
    return new Callable < CustomersListDTO > () {

        @Override
        public CustomersListDTO call() throws Exception {
            Thread.sleep(2000);
            return customerService.getAllCustomers();
        }

    };
}
Run Code Online (Sandbox Code Playgroud)

我的同步休息客户端方法:

public Response get_all_customers() {
    ResponseEntity < CustomersListDTO > response;
    try {
        response = restTemplate.getForEntity(
            getMethodURI(ServiceExplanation.GET_ALL_CUSTOMERS),
            CustomersListDTO.class
        );
        message = "Customers obtained successfully!";
    } catch (HttpServerErrorException ex) {
        message = "ERROR: " + ex.getMessage() + " - " + ex.getResponseBodyAsString();
    } catch (HttpClientErrorException ex) …
Run Code Online (Sandbox Code Playgroud)

java rest spring asynchronous resttemplate

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

asynchronous ×1

java ×1

rest ×1

resttemplate ×1

spring ×1