如何编写异步休息客户端?我的控制器(不确定它是不是因为异步).
@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)