查看依赖
查看使用的openfeign版本是否已包含feign-form和feign-form-spring
没有则在pom.xml里添加依赖
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>3.3.0</version>
</dependency>
FeignClient
@PostMapping添加consumes = MediaType.MULTIPART_FORM_DATA_VALUE
feign接口和对应的被调用接口的参数要加上@RequestPart
@PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Response uploadFile(@RequestPart("file") MultipartFile file);
MultipartSupportConfig
@FeignClient 添加配置 configuration= MultipartSupportConfig.class
@Configuration
public class MultipartSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
版权声明:本文为weixin_39736281原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。