远程调用服务

远程调用服务,第1张

远程调用服务

引入open-feign的maven包

<dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-openfeignartifactId>
        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"));
    }

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/920254.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存