package com.nobodyiam.spring.in.action.reservation.client;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Jason on 5/5/16.
 */
@EnableZuulProxy
@EnableCircuitBreaker
@EnableDiscoveryClient
@SpringBootApplication
public class ReservationClientApplication {
  @Bean
  CommandLineRunner runner(DiscoveryClient dc) {
    return args -> {
      dc.getInstances("reservation-service")
              .forEach(si -> System.out.println(String.format(
                      "Found %s %s:%s", si.getServiceId(), si.getHost(), si.getPort())));
    };
  }

  @LoadBalanced
  @Bean
  RestTemplate restTemplate() {
    return new RestTemplate();
  }

  public static void main(String[] args) {
    SpringApplication.run(ReservationClientApplication.class, args);
  }
}

@@ -623,16 +623,71 @@
 n.Bean;%0A
+import org.springframework.context.annotation.Primary;%0A
 import o
@@ -1193,21 +1193,199 @@
 %0A%0A  
-@LoadBalanced
+/**%0A   * The load balanced rest template%0A   */%0A  @LoadBalanced%0A  @Bean%0A  RestTemplate loadBalanced() %7B%0A    return new RestTemplate();%0A  %7D%0A%0A  /**%0A   * The normal rest template%0A   */%0A  @Primary
 %0A  @

add comment