远程调用服务
引入open-feign的maven包
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
编写一个接口,告诉SpringCloud这个接口需要调用远程服务
声明接口的每一个方法都是调用哪个远程服务的哪个请求
@FeignClient("gulimall-coupon")
public interface CouponFeignService {
@RequestMapping("coupon/coupon/member/list")
public R membercoupons();
}
开启远程调用功能
主启动类加@EnableFeignClients
@EnableFeignClients(basePackages = "com.li.gulimall.member.feign")
Test
@Autowired
CouponFeignService couponFeignService;
@RequestMapping("/coupons")
public R test(){
MemberEntity memberEntity = new MemberEntity();
memberEntity.setNickname("张三");
R membercoupons = couponFeignService.membercoupons();
return R.ok().put("member", membercoupons).put("coupons", membercoupons.get("coupons"));
}