1.導(dǎo)入依賴企锌,這個(gè)version是依賴spring cloud的
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.在調(diào)用方創(chuàng)建一個(gè)feign包,創(chuàng)建一個(gè)service類泳猬,在類上添加注解@FeignClient("mail-coupon") mail-coupon是要調(diào)用的服務(wù)的名稱方库,并編寫方法钮糖,方法上添加調(diào)用服務(wù)的地址宴猾,即調(diào)用哪個(gè)微服務(wù)的哪個(gè)請(qǐng)求
@FeignClient("mail-coupon")
public interface CouponFeignService {
@RequestMapping("/mailcoupon/coupon/member/list")
public R memberCoupons();
}
3.在微服務(wù)的主程序類上開啟注解,并指明服務(wù)在哪個(gè)包下
@EnableFeignClients("com.yuchen.yuchenmail.mailmember.feign")