Feign-Form Encoder-实现基于Spring MultipartFile 和Spring FeignClient 表单文件上传
OpenFeign Form Encoder 支持对application/x-www-form-urlencoded and multipart/form-data 格式的表单数据编码。支持基于Spring MultipartFile 和Spring Cloud Netflix @FeignClient框架的表单文件上传。
1、在 pom.xml文件引入如下依赖:
<dependencies>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>3.8.0</version>
</dependency>
</dependencies>
2、如何使用FeignForm Encoder
@FeignClient(
name = "file-upload-service",
configuration = FileUploadServiceClient.MultipartSupportConfig.class
)
public interface FileUploadServiceClient extends IFileUploadServiceClient {
public class MultipartSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;