When i tried to consume from my first springboot application to another via RestTemplate getting below error from postman
Request URI: http://localhost:8083/template/getprodgsspringboot
"timestamp": "2019-03-15T10:02:39.168+0000",
"status": 500,
"error": "Internal Server Error",
"message": "I/O error on GET request for \"http://localhost:8080/products\": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect",
"path": "/template/getprodgsspringboot"
First spring boot Application : Rest controller
@RequestMapping("/template/getprodgsspringboot")
public String getProductList() {
HttpHeaders headers=new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> http=new HttpEntity<>(headers);
return resttemplate.exchange("http://localhost:8080/products",HttpMethod.GET,http,String.class).getBody();
}
Second Spring boot Application :Rest controller
//GET Method of rest webservice
@RequestMapping("/products")
public ResponseEntity<Object> getMethod(){
System.out.println("My GET http method");
retu
Please use the below resttemplate and give a try. It should work
ResponseEntity result = restTemplate.exchange(" http://localhost:8080/products ", HttpMethod.GET, http, String.class);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.