openfeign

一、要使用feign远程调用首先在当前微服务中pom文件中引入(也可以在生成springboot的时候勾选openfeign)

<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

二、编写接口告诉springcloud这个接口需要远程服务

  声明接口的每一个方法都是调用哪个远程服务的请求

 

 

 

package com.xinghua.thanosmall.member.feign;


import com.xinghua.common.utils.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
//远程调用的服务名称
@FeignClient("thanosmall-coupon")
public interface CouponFeignService {
  //远程调用的微服务下的方法 @RequestMapping(
"/coupon/coupon/menber/list") public R membercoupons(); }

三、开启远程调用功能

  首先两个服务都需要启动上线并且加入nacos注册中心即可实现远程调用

 

/**  两个微服务**/

 

 nacos

 

posted @ 2021-03-25 15:21  别想这么多  阅读(347)  评论(0)    收藏  举报