美文网首页
服务引用feign

服务引用feign

作者: Nick_4438 | 来源:发表于2018-08-19 22:52 被阅读0次

前言

本文介绍如何使用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;
    }
}

相关文章

网友评论

      本文标题:服务引用feign

      本文链接:https://www.haomeiwen.com/subject/mxphiftx.html