1.pom依赖
<dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>io.github.openfeign.form</groupId> <artifactId>feign-form-spring</artifactId> <version>3.0.1</version> </dependency>
2.MultipartSupportConfig配置类
@Configuration public class MultipartSupportConfig { @Autowired private ObjectFactory<HttpMessageConverters> messageConverters; @Bean public Encoder feignFormEncoder() { return new SpringFormEncoder(new SpringEncoder(messageConverters)); } }
3.后端接口改造
关键字consumes = MULTIPART_FORM_DATA_VALUE
@PostMapping(value = "uploadExamTarget", consumes = MULTIPART_FORM_DATA_VALUE)
public JsonResult uploadExamTarget(@RequestBody MultipartFile file) {
return new JsonResult(coreClient.uploadExamTarget(file));
}
4.FeignClient接口改造
引入配置类MultipartSupportConfig,和接口注解consumes = MULTIPART_FORM_DATA_VALUE
@FeignClient(value = "core-server", configuration = MultipartSupportConfig.class) public interface CoreClient { @RequestMapping(value = "/excel/uploadExamTarget", consumes = MULTIPART_FORM_DATA_VALUE) String uploadExamTarget(@RequestBody MultipartFile file); }