spring cloud feign 坑
feign是啥?
很多人可能对于feign 不是很熟悉,可以看一下其他网友的实例分享:spring cloud feign简介
如果觉得上面这个比较难的话,还有一个简单入门的:spring cploud feign使用详解
今天的主题是记录遇到的坑,关于feign的资料网友分享已经很详细,我就不班门弄斧啦啦
feign 坑之@RequestParam参数名
这次在做一个中台项目(使用 spring boot),需要和市场上很多同行公司结合的那种,这就涉及到同个服务需要被很多外部服务调用的场景,之前通常都会用代理去实现对其他外部服务的访问,但代理模块也需要写很多代码,对于懒惰的程序员而言,这当然是要想办法简化的(是谁说的,不会偷懒的程序员都不是好程序员来着?)
然后有大神推荐我们使用了feign,Feign 是 Spring Cloud的组件,这里就需要讨论spring boot 和spring cloud 整合的问题了,但是不展开,可以移步扩展阅读。
在依赖了 spring cloud之后,外部服务就可以愉快的开始使用 feign来调用我们的接口了
@FeignClient(name = "${test-service.application.name}", configuration = TestServiceFeignConfig.class)
public interface TestServiceInterfaceClient extends TestServiceInterfaceApi{
}
TestServiceInterfaceApi 是我们中台内部实现的接口,接口定义如下:
/**
* 版权所有(C),xxxx公司,2019,所有权利保留。
*
* 项目名: test-client-api
* 文件名: TestServiceApi.java
* 模块说明:
* 修改历史:
* 2019年6月20日 -ln- 创建。
*/
package com.xxxx.test.client.api.test; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*; import java.util.List; /**
* xxxxx服务
*
* @author ln
*
*/
@Api(tags = "xxxxx服务")
@RequestMapping(value = "service/test",
produces = "application/json;charset=utf-8")
public interface TestServiceInterfaceApi { /**
* 查询
*
* @param id1
* id1
* @param filter
* 查询条件
* @return 查询结果
*/
@ApiOperation(value = "查询")
@RequestMapping(value = "/query", method = RequestMethod.POST)
@ResponseBody
Response<List<TestEntity>> query( //
@ApiParam(required = true) @PathVariable("id1") String id1,
@ApiParam(required = true) @RequestBody TestFilter filter); /**
* 批量移除
*
* @param id1
* id1
* @param modifition
* 处理内容
* @return 处理结果
*/
@ApiOperation(value = " 批量移除")
@RequestMapping(value = "/batchremove", method = RequestMethod.POST)
@ResponseBody
Response batchRemove( //
@ApiParam(required = true) @PathVariable("id1") String id1,
@ApiParam(required = true) @RequestBody TestBatchRemove batchRemove,
@ApiParam(required = true) @RequestParam String operator);
}
这时候,在外部系统服务里 @Autowired 一下 TestServiceInterfaceClient 就可以调用到我们的接口了,按道理讲这个流程应该顺畅无比,毕竟定义 feignClient 才这么几行代码,不可能出错,but 程序员不可能是不写bug 的~~
外部服务启动时,报错:

这个报错是说我们中台服务的某个接口的第2 个参数为空,但是我们本地的服务是正常启用的,内部调用无比顺畅,那,问题在哪?
经过排查,发现是我们接口定义用到了 @RequestParam 注解,但是Feign 对 @RequestParam 声明的参数未识别到,加上参数的名字之后,一切OK
/**
* 批量移除
*
* @param id1
* id1
* @param modifition
* 处理内容
* @return 处理结果
*/
@ApiOperation(value = " 批量移除")
@RequestMapping(value = "/batchremove", method = RequestMethod.POST)
@ResponseBody
Response batchRemove( //
@ApiParam(required = true) @PathVariable("id1") String id1,
@ApiParam(required = true) @RequestBody TestBatchRemove batchRemove,
@ApiParam(required = true) @RequestParam("operator") String operator);
}
后面找了找,发现前面也有很多人遇到了相似的问题,还有网友系统的整理了坑,具体可异步扩展阅读。
虽然这是一个很小的点,小菜依旧很开心(毕竟不用背锅啊)。
我们的中台功能在不断地发展全面,so这篇帖子将会不断更新....
扩展阅读
spring cloud feign 坑的更多相关文章
- RestTemplate OR Spring Cloud Feign 上传文件
SpringBoot,通过RestTemplate 或者 Spring Cloud Feign,上传文件(支持多文件上传),服务端接口是MultipartFile接收. 将文件的字节流,放入ByteA ...
- Spring cloud Feign 深度学习与应用
简介 Spring Cloud Feign是一个声明式的Web Service客户端,它的目的就是让Web Service调用更加简单.Feign提供了HTTP请求的模板,通过编写简单的接口和插入注解 ...
- Spring Cloud Feign 如何使用对象参数
概述 Spring Cloud Feign 用于微服务的封装,通过接口代理的实现方式让微服务调用变得简单,让微服务的使用上如同本地服务.但是它在传参方面不是很完美.在使用 Feign 代理 GET 请 ...
- 笔记:Spring Cloud Feign Ribbon 配置
由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...
- 笔记:Spring Cloud Feign Hystrix 配置
在 Spring Cloud Feign 中,除了引入了用户客户端负载均衡的 Spring Cloud Ribbon 之外,还引入了服务保护与容错的工具 Hystrix,默认情况下,Spring Cl ...
- 笔记:Spring Cloud Feign 其他配置
请求压缩 Spring Cloud Feign 支持对请求与响应进行GZIP压缩,以减少通信过程中的性能损耗,我们只需要通过下面二个参数设置,就能开启请求与响应的压缩功能,yml配置格式如下: fei ...
- 笔记:Spring Cloud Feign 声明式服务调用
在实际开发中,对于服务依赖的调用可能不止一处,往往一个接口会被多处调用,所以我们通常会针对各个微服务自行封装一些客户端类来包装这些依赖服务的调用,Spring Cloud Feign 在此基础上做了进 ...
- 第六章:声明式服务调用:Spring Cloud Feign
Spring Cloud Feign 是基于 Netflix Feign 实现的,整合了 Spring Cloud Ribbon 和 Spring Cloud Hystrix,除了提供这两者的强大功能 ...
- Spring Cloud Feign Ribbon 配置
由于 Spring Cloud Feign 的客户端负载均衡是通过 Spring Cloud Ribbon 实现的,所以我们可以直接通过配置 Ribbon 的客户端的方式来自定义各个服务客户端调用的参 ...
随机推荐
- JSSDK使用步骤
绑定域名 先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 备注:登录后可在“开发者中心”查看对应的接口权限. 引入js文件 在需要调用JS接口的页面引入如下JS文件,( ...
- 记录利用CSS完美解决前端图片变形问题
在头条IT学堂看到CSS完美解决前端图片变形问题的文章,就记录分享下: 一.让图片的宽度或者高度等于容器的宽度或高度,多余的裁掉,然后让图片居中: <style type="text/ ...
- J20170602-ts
アソシエーション association n. 联想; 协会,社团; 联合,联系; アンケート 英文是questionnaire
- robotframework - 基础关键词
robotframework基础关键词如下: 1.可在python.notepad++ 编辑: *** Settings *** *** Test Cases ***variable ${a} Set ...
- JavaScript--DOM删除节点removeChild()
删除节点removeChild() removeChild() 方法从子节点列表中删除某个节点.如删除成功,此方法可返回被删除的节点,如失败,则返回 NULL. 语法: nodeObject.remo ...
- Hdu 3487 play the chain
Description 瑶瑶很喜欢玩项链,她有一根项链上面有很多宝石,宝石从1到n编号. 首先,项链上的宝石的编号组成一个序列:1,2,3,...,n. 她喜欢两种操作: 1.CUT a b c:他会 ...
- 题解报告:hdu 1698 Just a Hook(线段树区间修改+lazy懒标记的运用)
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...
- 全志A33平台编译linux(分色排版)V1.1
全志A33平台编译linux 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/13 10:41 版本:V1.1 (一)解压缩lichee备用 ...
- 自定义 Java Annotation ,读取注解值
1. 首先是自定义注解: package cn.veji.hibernate.po; import java.lang.annotation.ElementType; import java.lang ...
- POJ_2387_最短路
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46859 Accepted ...