• 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);
        }
  • 相关阅读:
    SCOI2020游记
    关于我
    WC2020游记
    CSP-S 2019 游记
    回文自动机学习笔记
    全自动数字论证机(迫真)
    树状数组上二分
    《伊豆的舞女》 读书小记
    雅礼集训2019 Day5
    雅礼集训2019 Day4
  • 原文地址:https://www.cnblogs.com/junbaba/p/14060912.html
Copyright © 2020-2023  润新知