title: Microservices - RestTemplate UnknownHostException
body: <p>I have a simple setup with a Eureka service registration server, a service for the public API and a service that gets called from the public API using RestTemplate. Eureka tells me that the services are successfully registered, but when I call the service </p>
  
  <pre><code>@Service
  public class MyServiceService {
  
      @Autowired
      private RestTemplate restTemplate;
  
      private final String serviceUrl;
  
      public MyServiceService() {
          this.serviceUrl = "http://MY-SERVICE";
      }
  
      public Map&lt;String, String&gt; getTest() {
  
          Map&lt;String, String&gt; vars = new HashMap&lt;&gt;();
          vars.put("id", "1");
  
          restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
  
          return restTemplate.postForObject(serviceUrl+"/test", "", Map.class, vars);
      }
  }
  </code></pre>
  
  <p>I get the following exception</p>
  
  <pre><code>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 POST request for "http://MY-SERVICE/test": MY-SERVICE;
    nested exception is java.net.UnknownHostException: MY-SERVICE] with root cause java.net.UnknownHostException: MY-SERVICE
  </code></pre>
  
  <p>I created a sample project to illustrate my setup, maybe someone could take a look at it and tell me what's wrong with my setup.</p>
  
  <p><a href="https://github.com/KenavR/spring-boot-microservices-example" rel="noreferrer">https://github.com/KenavR/spring-boot-microservices-example</a></p>
  
  <p>thanks</p>