Rest java.net.ConnectException:同时连接两个Spring Boot应用程序

问题描述 投票:0回答:1

当我试图从我的第一个春季启动应用程序消费到另一个通过RestTemplate从邮递员获得以下错误

请求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"

第一次春季启动应用:休息控制器

@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();
}

第二个Spring启动应用程序:Rest控制器

//GET Method of rest webservice
@RequestMapping("/products")
public ResponseEntity<Object> getMethod(){
    System.out.println("My GET http method");
    retu
java spring rest spring-boot webservice-client
1个回答
0
投票

请使用下面的resttemplate并试一试。它应该工作

ResponseEntity result = restTemplate.exchange(“http://localhost:8080/products”,HttpMethod.GET,http,String.class);

© www.soinside.com 2019 - 2024. All rights reserved.