您的位置:首页 > Web前端

如何使用feign调用服务

2020-02-12 16:04 465 查看

第一步添加依赖

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

第二步:启动类上新增注解

@EnableFeignClients

第三步:新增ProductClient接口内容如下:

//设置访问服务名product
@FeignClient(name = "product")
public interface ProductClient {

@GetMapping("/msg")  //表示访问的服务下的接口名msg
String productMsg();
}

第四步:调用服务

@Autowired
private ProductClient productClient;

@GetMapping("getProductMsg")
public String getProductMsg() {
String response = productClient.productMsg();
log.info("response={}",response);
return response;
}
  • 点赞
  • 收藏
  • 分享
  • 文章举报
qq_35565675 发布了7 篇原创文章 · 获赞 0 · 访问量 156 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: