用RestTemplate.exchange做微服务请求时遇到的问题:
LocalDateTime dt = LocalDateTime.of(2019,02,20,11,00,00);
log.info("创建的LocalDateTime: "+dt);
String url ="http://localhost:5050/omc/ue/state/pageable/2/600";
//UE_STATUS_ADDRESS + String.format("/1/2000");
PdUeStatusPara p =new PdUeStatusPara();
p.setData(dt);
HttpEntity entity =new HttpEntity(p,null);
log.info("组合体:"+ entity);
ParameterizedTypeReference> responseType =
new ParameterizedTypeReference>() { };
/*需要传递的参数:当前系统时间-15min,外加Pageable*/
ResponseEntity> result =
restTemplate.exchange(url, HttpMethod.POST, entity/*httpEntity*/, responseType);


500 的状态码表示服务器端在执行请求时发生错误,也有可能是Web应用存在的Bug或某些临时性故障。
明天继续调试,解决了再来记录。

如果故意写错url,结果如上图,排除 500 错误是因为url不对。
/*第三个参数传入null的情况*/
/*需要传递的参数:当前系统时间-15min,外加Pageable*/
ResponseEntity> result =
restTemplate.exchange(url, HttpMethod.POST,null/*httpEntity*/, responseType);

加入headers,头部信息是格式信息;



离真相更近了一步。
从报错的信息中可以知道这个错误和com.fasterxml.jackson.databind有关,猜测是json转java对象时有问题。
修改办法参考:https://stackoverflow.com/questions/34647303/spring-resttemplate-with-paginated-api

问题解决了。
网友评论