1.引入
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
2.启动类加上注解(basePackages指定的是第三步接口的位置)
@EnableFeignClients(basePackages = "com.gulimall.member.fegin")
3.编写接口
/**
* @author lbb
* path: 统一前缀
* name: 服务名称
*/
@FeignClient(name = "gulimall-coupon",path = "/coupon")
public interface CouponFeignService {
@GetMapping("/test")
String test001();
}
4.调用
@RestController
@RequestMapping("/member")
public class TestController {
@Resource
CouponFeignService couponFeignService;
@GetMapping("/feign")
public String feign() {
return "member远程调用:"+couponFeignService.test001();
}
}
视频地址https://www.bilibili.com/video/BV1np4y1C7Yf?p=22