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);
        }
  • 相关阅读:
    Java练习题
    循环练习
    Java String类详解
    Collections类
    TreeSet类
    IOS基础:NSTimer类的使用
    IOS基础:深入理解Objectivec中@class的含义
    IOS基础:retain,copy,assign及autorelease
    IOS基础:ActionSheet(上拉菜单)的实现
    Xcode 模拟器生成目标目录位置查找
  • 原文地址:https://www.cnblogs.com/junbaba/p/14060912.html
Copyright © 2011-2022 走看看