zoukankan      html  css  js  c++  java
  • spring cloud-Feign支持接口继承方式快速生成客户端【代码结构】

    本文重在理解这个代码结构:

    文章来自:https://blog.csdn.net/lh87270202/article/details/100990482

    1、接口定义,注意feign接口不能再继承其它接口,这个接口定义包需要抽象出公共的api jar,
    当然包括请请求对象和返回对象都需要抽象成公共包,
    消费者在定义feign客户端的时候,需要定义一个RefactService继承这个interface。
     这样在消费端才不用重复定义feign的接口
    public interface TestFeignService{
        @PostMapping("testFeign")
        String testFeign(@Param("param1")String param1);
        @PostMapping("testFeign1")
        void testFeign1();
    }
    
    2、实现接口,用restController注解
    @RestController
    public class TestFeignServiceImpl implements TestFeignService {
        @Override
        public String testFeign(String param1) {
            System.out.println("接收参数");
            System.out.println(param1);
            return "ok";
        }
        @Override
        public void testFeign1() {
            System.out.println("testFeign1");
        }
    }
    
    3、消费者Feign客户端定义
    引入TestFeignService  api接口定义
    @FeignClient(name = "test-feign")
    public interface RefactTestFeignService extends TestFeignService {
    }
    
    4、调用
        @Autowired
        private RefactTestFeignService refactTestFeignService;
        @Test
        public void test(){
            String restul = refactTestFeignService.testFeign("20190918");
            System.out.println("========================");
            System.out.println(restul);
        }
  • 相关阅读:
    表单提交方式
    js--dom对象
    js--bom对象
    css布局的漂浮、position定位
    python语法学习第五天--lambda表达式、filter()、map()
    python语法学习第五天--函数(2)
    python3语法学习第五天--函数(1)
    python3语法学习第四天--序列
    leetcode| 84. 柱状图中最大的矩形
    leetcode| 56. 合并区间
  • 原文地址:https://www.cnblogs.com/junbaba/p/14060912.html
Copyright © 2011-2022 走看看