服务引用feign

前言

本文介绍如何使用fegin 调用服务。

操作步骤

  • 添加fegin依赖
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
  • 应用启动类加注解 @EnableFeignClients

  • 声明feign相关接口

@FeignClient(name = "product")
public interface ProductClient {
    @GetMapping("/msg") //访问product下面msg这个接口
    String productMsg();
}
  • 调用访问服务
public class ClientController {

    @Autowired
    private ProductClient productClient;

    @GetMapping("/getProductMsg")
    public String getProductMsg() {
        String response = productClient.productMsg();
        log.info("resoponse={}", response);
        return response;
    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,987评论 19 139
  •  通过前面两章对Spring Cloud Ribbon和Spring Cloud Hystrix的介绍,我们已经掌...
    Chandler_珏瑜阅读 213,796评论 15 140
  • 秋子很愁,一愁就开始揪头发,一揪总是一大把,看着本来就不太结实的头发分叉开花,发叉的头发从中间开出枝丫,没有什么营...
    奇非其阅读 448评论 2 2
  • 三年三班孙宇萌读书《弟孑规》时间长30分钟
    浅色夏天_cd48阅读 351评论 0 0
  • 这是一场雨,来的刚刚好,天不黑只是云很灰,有点风,把这雨送到脸上来。虽然我有伞,可我不想遮。路人很奇怪,目光常常瞟...
    过者不过阅读 174评论 1 1