1:Rest + Ribbon 

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

    public String hiService(String name) {
        return restTemplate.getForObject("http://hi-service/hi?name="+name,String.class);
    }

 

2:Fegin默认 集成Ribbon

//控制器    
  @Autowired SchedualServiceHi schedualServiceHi; @RequestMapping(value
= "/hi",method = RequestMethod.GET) public String sayHi(@RequestParam String name){ return schedualServiceHi.sayHiFromClientOne(name); }
// 添加一个接口方法
@FeignClient(value = "hi-service") public interface SchedualServiceHi { @RequestMapping(value = "/hi",method = RequestMethod.GET) String sayHiFromClientOne(@RequestParam(value = "name") String name); }

 

posted on 2018-04-13 13:17  1161588342  阅读(295)  评论(0编辑  收藏  举报