Feign远程调用Multipartfile参数处理
作者:唐文军 时间:2022-09-22 02:46:24
Feign远程调用Multipartfile参数
今天在写业务代码的时候遇到的问题, 前端请求A服务,能正确把参数给到A服务<参数里面包括文件类型的 Multipartfile>,但是当A服务调用B服务时把文件参数丢过去,那边接收不到,并且会报Multipartfile 参数错误。
在网上找到了答案,特此记录一下:
解决方案
必须的
在你的fegin 服务接口暴露的地方新建一个配置类。
package com.gobon.gbjk.file.api.config;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* <p>
* feign配置类
* </p>
*
* @projectName: gbjk-user
* @package: com.gobon.gbjk.file.api.config
* @className: FeignSupportConfig
* @author: wen jun tang
* @date: 2021年12月21日 12:25
* @version: 1.0
*/
@Configuration
public class FeignSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public SpringFormEncoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
然后你的接口 文件参数用@RequestPart修饰:
@PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
AjaxResult upload(@RequestPart("file") MultipartFile file, @RequestParam("bucketName") String bucketName);
再次调用, 完美解决!
Feign远程调用传参问题
如果是简单参数,用@RequestParam或者@PathVariable注解
如果是对象参数,用@RequestBody注解
来源:https://blog.csdn.net/Ambitiouss/article/details/122069471
标签:Feign,远程调用,Multipartfile,参数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
关于springboot 中使用httpclient或RestTemplate做MultipartFile文件跨服务传输的问题
2023-01-04 15:38:04
![](https://img.aspxhome.com/file/2023/0/110790_0s.jpg)
Android屏幕适配工具类 Android自动生成不同分辨率的值
2022-03-07 13:45:39
![](https://img.aspxhome.com/file/2023/7/137607_0s.jpg)
Android百度地图实现搜索和定位及自定义图标绘制并点击时弹出泡泡
2023-08-30 21:30:38
![](https://img.aspxhome.com/file/2023/7/129017_0s.png)
java中mybatis和hibernate的用法总结
2022-08-23 07:24:38
Android开发实现判断通知栏是否打开及前往设置页面的方法
2022-10-21 10:43:45
Android中实现GPS定位的简单例子
2021-11-24 21:01:25
Android Studio新建工程默认在build.gradle中加入maven阿里源的问题
2023-04-02 06:33:32
![](https://img.aspxhome.com/file/2023/0/129120_0s.jpg)
java图片色阶调整和亮度调整代码示例
2023-02-24 16:35:33
Android实现带节点的进度条
2022-01-16 08:58:02
![](https://img.aspxhome.com/file/2023/0/108240_0s.jpg)
Android手机开发设计之记事本功能
2023-12-10 21:47:00
![](https://img.aspxhome.com/file/2023/2/138102_0s.jpg)
java 文件流的处理方式 文件打包成zip
2022-07-08 12:43:03
![](https://img.aspxhome.com/file/2023/5/125575_0s.png)
浅谈Java内存区域与对象创建过程
2022-08-31 17:56:25
java用接口、多态、继承、类计算三角形和矩形周长及面积的方法
2021-10-24 22:15:46
Android开发之绘制平面上的多边形功能分析
2023-12-13 13:31:57
C#使用Monitor类实现线程同步
2021-07-20 03:01:14
![](https://img.aspxhome.com/file/2023/3/67553_0s.png)
Android仿QQ、微信聊天界面长按提示框效果
2023-06-11 14:04:32
![](https://img.aspxhome.com/file/2023/8/122088_0s.jpg)
Android编程中自定义dialog用法实例
2023-05-10 07:21:37
Java中的双重检查(Double-Check)详解
2023-02-23 21:05:23
C#通过NPOI操作Excel的实例代码
2022-01-20 17:26:29
![](https://img.aspxhome.com/file/2023/1/119601_0s.png)
说说@ModelAttribute在父类和子类中的执行顺序
2022-07-31 17:59:55