2、(ribbon) ----@loadbalancer 实例
i)、OrderService
@RestController
public class OrderService {
@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private RestTemplate restTemplate;
@Autowired
private LoadBalancer loadBalancer;
@Resource
private LoadBalancerClient loadBalancerClient;
@RequestMapping("/orderToMember")
public String orderToMember(){
String resutl3=restTemplate.getForObject("http://provider2004/hello/123131321312",String.class);
return "调用provider2004-20004 返回结果:"+resutl3;
}
}
2)、Consumer2018Application
public class Consumer2018Application {
public static void main(String[] args) {
SpringApplication.run(Consumer2018Application.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
}