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); }