1
在我的REST HTTP调用的Spring-boot项目中,我使用了org.springframework.web.client.RestTemplate。如何停止org.springframework.web.client.RestTemplate缓存响应?
问题是它缓存响应,这意味着当我第一次调用它时,我得到了正确的响应,但是当我更新与当前API相关的服务器上的数据时,以及当我调用相同的API第二次它仍然返回我旧的响应,因此它可能从缓存中取出ResponseEntity<T>
?我不确定。如何在每次调用相同的API时获取最新版本的响应?
这是我如何让HTTP调用
public <T> ResponseEntity<T> doQueryApi(String url, HttpMethod httpMethod, Object anyObject, HttpHeaders requestHeaders, Class<T> responseType) throws RestClientException {
HttpEntity requestEntity = new HttpEntity(anyObject, requestHeaders);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<T> responseEntity = restTemplate.exchange(url, httpMethod, requestEntity, responseType);
return responseEntity;
}
}
您确定RestTemplate是缓存而不是服务器本身? AFAIK如果你不配置缓存,RestTemplate不会自行完成。 – dunni