解决feign实现微服务间的文件上传出现错误the request was rejected because no multipart boundary was found

项目最开始的依赖 

<dependency>
	<groupId>io.github.openfeign.form</groupId>
	<artifactId>feign-form-spring</artifactId>
	<version>3.2.2</version>
</dependency>
<dependency>
	<groupId>io.github.openfeign.form</groupId>
	<artifactId>feign-form</artifactId>
	<version>3.2.2</version>
</dependency>
<dependency>
	<groupId>commons-fileupload</groupId>
	<artifactId>commons-fileupload</artifactId>
	<version>1.3.3</version>
</dependency>

说一下我怎么解决的吧,feign接口,配置,controller和参考的例子大同小异,

我是跟踪源码发现content-type会被","或";"进行转换为Map,跟踪代码为org.apache.tomcat.util.http.fileupload.FileUploadBase#getBoundary

截图

在org.apache.tomcat.util.http.fileupload.FileUploadBase.FileItemIteratorImpl#FileItemIteratorImpl抛出异常

 

请求头中内容为 

//用户所调用的接口提交的content-type
multipart/form-data; boundary=--------------------------381278542566024683689443
//经过feign转发请求后的content-type,按英文逗号拆分刚好Map没有boundary为key的值,索引报错
multipart/form-data, multipart/form-data; charset=UTF-8; boundary=16f0f6d2c45

希望对大家有所帮助

解决方法为修改feign-form的版本

<dependency>
	<groupId>io.github.openfeign.form</groupId>
	<artifactId>feign-form-spring</artifactId>
	<version>3.6.0</version>
</dependency>
<dependency>
	<groupId>io.github.openfeign.form</groupId>
	<artifactId>feign-form</artifactId>
	<version>3.6.0</version>
</dependency>
<dependency>
	<groupId>commons-fileupload</groupId>
	<artifactId>commons-fileupload</artifactId>
	<version>1.3.3</version>
</dependency>

 

 我的feign版本为

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-openfeign</artifactId>
	<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
	<version>2.1.1.RELEASE</version>
</dependency>

参考的例子:

https://my.oschina.net/zyldsy/blog/1808419

https://www.jianshu.com/p/4ed2ac47d2f7

https://blog.csdn.net/Day_Day_No_Bug/article/details/90243042

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
出现异常"could not extract response: no suitable httpclient found for response type"通常是由于open-feign微服务调用时,没有找到合适的http客户端来处理返回的响应类型引起的。 在使用open-feign进行微服务调用时,我们需要根据实际情况选择适合的http客户端来处理响应。通常open-feign会自动进行http客户端的选择和配置,但有些情况下可能会出现上述异常。 解决该异常的方法有以下几种: 1. 确保引入了适当版本的open-feign和相关依赖库。要使用open-feign,应该在pom.xml文件中添加相应的依赖,并确保其版本与当前使用的spring boot版本兼容。 2. 检查http客户端的配置。可以通过修改application.properties或application.yml文件设置http客户端的配置。例如,在application.properties文件中添加以下配置: ``` feign.httpclient.enabled=true feign.okhttp.enabled=false ``` 这将启用Apache HttpClient并禁用OkHttp客户端。 3. 如果仍然出现异常,可以尝试清除本地maven仓库并重新构建项目。有时候这种异常是由于maven仓库中缓存的库与实际所需版本不一致引起的。 总的来说,解决open-feign微服务调用异常"could not extract response: no suitable httpclient found for response type"的方法是确保使用了适当的open-feign版本,并根据需要调整http客户端的配置。如果仍然出现异常,可以尝试清除maven仓库并重新构建项目。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值