title: SpringBoot: @HystrixCommand not working
body: <p>Fallback method specified with <code>@HystrixCommand</code> is not invoked when configured with Eureka/Ribbon aware RestTemplate is used.</p>
  
  <p>pom.xml</p>
  
  <pre><code>....
  &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-eureka&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-hystrix&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-ribbon&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-bus-amqp&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-feign&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-amqp&lt;/artifactId&gt;
          &lt;/dependency&gt;
  ....
  </code></pre>
  
  <p><code>@SpringBootApplication</code> config</p>
  
  <pre><code>@SpringBootApplication
  @EnableDiscoveryClient
  @EnableCircuitBreaker
  @EnableHystrix
  public class FileUploadServiceApplication {
     ...
      @Bean
      @LoadBalanced
      public RestTemplate restTemplate() {
          return new RestTemplate();
      }
    ...
  }
  
  @Component
  @RefreshScope
  public class FileUploadServiceImpl implements FileUploadService {
   ....
  @HystrixCommand(fallbackMethod = "fallbackToMessageQ")
      private void notifyComplete(String fileName) {
       this.restTemplate.exchange(
                      "http://DISCOVERY-CLIENT/api/file/process?filename="+fileName, ....)
        ....
      }
      private void fallbackToMessageQ(String fileName, Throwable t) {
          System.out.println("notify threw exception, "+t.getMessage());
          rabbitTemplate.convertAndSend(uploadCompleteExchangeName, "", fileName.getBytes());
      }
  }
  </code></pre>
  
  <p>when executed it ends just after throwing IllegalStateException for unable to access <code>DISCOVERY-CLIENT</code> and never going to access the fallback method, let me know if I have to configure anything else.</p>
  
  <pre><code>java.lang.IllegalStateException: No instances available for DISCOVERY-CLIENT
          at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:90)
          at org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor$1.doWithRetry(RetryLoadBalancerInterceptor.java:88)
          at org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor$1.doWithRetry(RetryLoadBalancerInterceptor.java:76)
          at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:286)
          at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:163)
  </code></pre>