I have two microservices and I want that one consumes of the other but I'm obtaining this mistake:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/testMicroservicio": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)] with root cause
java.net.ConnectException: Connection refused (Connection refused)
However if I execute the url in the browser, it works perfectly but if a microservice wants to access to the other microservice, I have this mistake.
Does someone kown why?
I'm consuming with: RestTemplate
I put some of code:
@RestController
public class MicroServiceController {
private final AddressService service;
private static final String URL_API_INFO = "http://localhost:8080/testMicroservicio";
private RestTemplate restTemplate = new RestTemplate();
private final static Logger log = Logger.getLogger("com.bernanetwork.web.controller.MicroServiceController");
@Autowired
public MicroServiceController(AddressService service) {
this.service = service;
}
@RequestMapping(value = "/micro-service-test")
public String consumidor() throws Exception {
log.info("----------------------------------------------------------------------------------------");
log.info("-------------------------Iniciando método consumidor------------------------------------");
log.info("----------------------------------------------------------------------------------------");
ResponseEntity <PruebasMicroservicio[]> response = restTemplate.getForObject(URL_API_INFO, PruebasMicroservicio[].class);
Arrays.asList(response.getBody()).forEach(info -> log.info("---"+info));
return "ok";
}
These microservices are running in Docker
Thanks so much.