[英]Rest java.net.ConnectException : while connecting two SpringBoot application
When i tried to consume from my first springboot application to another via RestTemplate getting below error from postman 当我试图通过RestTemplate从我的第一个springboot应用程序消费到另一个应用程序时,从邮递员获得以下错误
Request URI: http://localhost:8083/template/getprodgsspringboot 请求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 第二个Spring启动应用程序:Rest控制器
//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. 请使用下面的resttemplate并试一试。 It should work
它应该工作
ResponseEntity result = restTemplate.exchange(" http://localhost:8080/products ", HttpMethod.GET, http, String.class); ResponseEntity result = restTemplate.exchange(“ http:// localhost:8080 / products ”,HttpMethod.GET,http,String.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.