@LoadBalanced:该注解可以实现Ribbon和RestTemplate的结合,实现负载均衡的功能
@Bean @LoadBalanced public RestTemplate restTemplate(){ builder.setConnectTimeout(20*1000) .setReadTimeout(60*1000); return builder.build(); }return restTemplate.getForObject("http://localhost:8082/user/selectAll",String.class);换为return restTemplate.getForObject("http://service-provider/user/selectAll",String.class);实现了通过微服务名称调用服务
public String selectAll(){ //return restTemplate.getForObject("http://localhost:8082/user/selectAll",String.class); return restTemplate.getForObject("http://service-provider/user/selectAll",String.class); }微服务调用返回结果不变