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中调用kettle转换文件
    开源游戏引擎体验
    cocos2d-x 托付模式的巧妙运用——附源代码(二)
    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 Windows Phone
    redis String结构
    Redis 键命令
    Redis 基础命令
    linux curl 命令的使用
    将spring boot项目部署到tomcat容器中
    Redis常用命令
  • 原文地址:https://www.cnblogs.com/junbaba/p/14060912.html
Copyright © 2011-2022 走看看