一、快速创建springboot项目集成cloud包
二、pom中加入feign相关jar包
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId></dependency>
三、项目启动类配置添加注解 @EnableFeignClients 启用feignclient
四、编写接口controller
package com.ang.feign.controller;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * @author: xiuxian.wang * @description: * @date: 2019/10/30 /@RestController@RequestMapping("/ang")public class AngController { @PostMapping("/feign") public String angFeign(@RequestBody String ang){ ang += "ang de fan ying"; return ang; }}
五、编写client
package com.ang.feign.client;import org.springframework.cloud.openfeign.FeignClient;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestBody;/ * @author: xiuxian.wang * @description: * @date: 2019/10/30 **/@FeignClient(value = "AngClient",url = "http://localhost:5214/ang/feign")public interface AngClient { @PostMapping String angReq(@RequestBody String ang);}
六、编写测试类
@Testvoid contextLoads() { String req = client.angReq("hello ang and "); log.info("ang client response info {}",req);}
七、源码地址:https://gitee.com/leisure-w/ang-feign.git
快速搭建feign远程调用客户端
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 大纲 注册中心功能服务one功能服务two 整体目录结构如下整体目录结构这里整个功能是一个maven项目,注册中心...
- 上一篇集成了ZuulGateway和Eureka并进行了测试。在实际场景中,我们肯定会有很多的微服务,而他们之间可...
- 1.Feign概述 在上一篇的HelloService这个类中,我们有这样一行代码: return r...