zoukankan      html  css  js  c++  java
  • Spring cloud 两种服务调用方式(Rest + Ribbon) 和 Fegin方式

    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); }
  • 相关阅读:
    进制转换
    BZOJ 1232 安慰奶牛题解
    [BeiJing wc2012]冻结 题解
    the Captain题解;
    最佳贸易
    第二短路
    街道赛跑
    图论基础知识.
    Tkinter 之事件绑定
    Tkinter 之TopLevel顶级窗口
  • 原文地址:https://www.cnblogs.com/eason-d/p/8819705.html
Copyright © 2011-2022 走看看