1.服务生产方

生产方方法示例
@RequestMapping("/member/list")
    public R memberCoupon(){
        CouponEntity couponEntity = new CouponEntity();
        couponEntity.setCouponName("满一百减十");
        return R.ok().put("coupons", Collections.singletonList(couponEntity));
    }

2.服务消费方

2.1引入openfeign

2.1.1 springbootApplication.java

开启远程调用
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class GulimallMemberApplication {

    public static void main(String[] args) {
        SpringApplication.run(GulimallMemberApplication.class, args);
    }

}

2.1.2 创建接口

image

编写一个接口,告诉 springcloud 这个接口需要远程服务
@FeignClient("gulimall-coupon") 其中,gulimall-coupon 为被调用的服务名——spring.applicaiton.name
@FeignClient("gulimall-coupon") //调用的服务名
public interface CouponFeignService {

    @RequestMapping("/coupon/coupon/member/list")
    public R memberCoupon();
}

3.结果

http://localhost:8000/member/member/coupons

image

如果觉得我的文章对你有用,请随意赞赏