1.openfeign概念
作为远程调用客户端,基于接口+注解调用服务使用
2.简单使用
- 添加注解
<!--引入openFeign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.启动类添加注解
@EnableFeignClients
3.创建feign服务接口,简单理解就是把调用服务的接口去掉{…}内容,如下
@GetMapping("/payment/get/{id}")
public CommonResult getPaymentById(@PathVariable("id") Long id);
特别注意,添加注解@FeignClient(value = “CLOUD-PAYMENT-SERVICE”)
value属性服务名
4.启动项目测试验证,远程调用是否成功。