美文网首页
快速搭建feign远程调用客户端

快速搭建feign远程调用客户端

作者: 王小胖v9 | 来源:发表于2020-03-23 15:08 被阅读0次

一、快速创建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远程调用客户端

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