@SuppressWarnings("unchecked")
public User getUser(String id,String name) {
SoftReference<RestTemplate> softRestTemplate = new SoftReference<RestTemplate>(restTemplate);
String url = null;
HashMap<String, String> uriVariables = new HashMap<String, String>();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<User> response=null;
Leaguer body=null;
try {
uriVariables.put("id", id);
uriVariables.put("name", name);
response = softRestTemplate.get().exchange(url,HttpMethod.GET, requestEntity, User.class, uriVariables);
body=response.getBody();
} catch (Exception e) {
e.printStackTrace();
}finally{
softRestTemplate = null;
}
return body;
}
softRestTemplate 2,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/yqlwl66/p/3811857.html