OpenFeign快速开始

1、pom.xml加入

<!-- openfeign -->
<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

2、启动类增加注解

@EnableFeignClients

3、创建接口类

@FeignClient(name = "stock", path = "/stock")
public interface StockFeignService {
    
    @RequestMapping("deduct")
    String deduct();
}

4、引入并调用接口

    @Autowired
    private StockFeignService stockFeignService;
    
    @RequestMapping("add")
    public String add(){
        System.out.println("下单成功!");
        
        String msg = stockFeignService.deduct();
        System.out.println(msg);
        
        return "hello world";
    }

 

posted @ 2022-04-01 16:34  yanglei.xyz  阅读(48)  评论(0)    收藏  举报