nacos-discovery依赖了ribbon,可以不用再引入ribbon依赖
    image.png
    2) 添加@LoadBalanced注解

    1. @Configuration
    2. public class RestConfig {
    3. @Bean
    4. @LoadBalanced
    5. public RestTemplate restTemplate() {
    6. return new RestTemplate();
    7. }
    8. }

    3) 修改controller

    1. @Autowired
    2. private RestTemplate restTemplate;
    3. @RequestMapping(value = "/findOrderByUserId/{id}")
    4. public R findOrderByUserId(@PathVariable("id") Integer id) {
    5. // RestTemplate调用
    6. //String url = "http://localhost:8020/order/findOrderByUserId/"+id;
    7. //模拟ribbon实现
    8. //String url = getUri("mall-order")+"/order/findOrderByUserId/"+id;
    9. // 添加@LoadBalanced
    10. String url = "http://mall-order/order/findOrderByUserId/"+id;
    11. R result = restTemplate.getForObject(url,R.class);
    12. return result;
    13. }