Как исправить ResourceAccessException в Spring приложении

Есть 2 микросервесных приложения, одно из которых обращается к другому. При сохранение аккаунта Postman выдает I/O error on POST request for "http://localhost:9999/accounts": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect. вот сервис где возникает ошибка

    @Service

public class CustomerService {


    private  final ObjectMapper objectMapper;

    @Autowired
    public CustomerService(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    public String saveCustomer(String name, String phone, String mail,
                             BigDecimal amount,  Boolean isOverdrawEnable) {
        AccountDTO accountDTO = new AccountDTO(name, phone, mail);
        String accountJson = null;
        try {
            accountJson = objectMapper.writeValueAsString(accountDTO);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();

        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> entity = new HttpEntity<>(accountJson, headers);

        ResponseEntity<String> stringResponseEntity = null;
        if (accountJson != null){
            stringResponseEntity =
                    restTemplate.postForEntity("http://localhost:9999/accounts", entity, String.class);

        }
        return stringResponseEntity == null  ?"-1" : (stringResponseEntity.getBody());
    }

с помощью брейк поинтов понял что ошибка возникает в

 stringResponseEntity =
                    restTemplate.postForEntity("http://localhost:9999/accounts", entity, String.class);

result в дебаге

Method trew 'org.springframework.web.client.ResourceAccessException' exception

Ответы (0 шт):