OpenFeign快速开始
1、pom.xml加入
<dependency> <groupId>org.springframework.cloudgroupId> <artifactId>spring-cloud-starter-openfeignartifactId> 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"; }