微服务之间的相互调用

我使用的是@FeignClient(name="com-kd-xxx")

首先添加maven依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-core</artifactId>
    <version>9.7.0</version>
</dependency>
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-slf4j</artifactId>
    <version>9.7.0</version>
</dependency>

然后编写服务之间调用的FeignClient代码

@FeignClient(name = "com-kd-hello")
public interface MyFeignClient{

    /**
     * 调用微服务的地址与请求类型
     */
    @RequestMapping(value = "/hello", method = RequestMethod.POST, headers = "Content-type=application/json")
    ResponseResult<List<ConsEntity>> queryConsList(@RequestBody ConsEntity cons);
}

使用方式

@Autowired
MyFeignClient myFeignClient;

然后myFeignClient.queryConsList(cons)就可以使用了

发布了11 篇原创文章 · 获赞 6 · 访问量 456

猜你喜欢

转载自blog.csdn.net/weixin_45993202/article/details/103694970