今天第一次遇到需要微服务之间传输MutipartFile的业务场景,网上找了一圈发现最终报错:ClassNotDfException: feign.Request$Body解决不了。
具体这样的,网上都差不多:
@Configuration public class MultipartSupportConfig { @Autowired private ObjectFactory<HttpMessageConverters> messageConverters; @Bean public Encoder feignFormEncoder() { return new SpringFormEncoder(new SpringEncoder(messageConverters)); } }
@FeignClient(name = "xxx", configuration = MultipartSupportConfig.class) @Component public interface CoreEurekaClient { @PostMapping(value = "/core/file/upload/{serverId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public void uploadFile(@RequestPart MultipartFile file, @PathVariable Integer serverId); }
@PostMapping("/upload/{serverId}") @ApiOperation("文件上传接口") public void uploadFile(@RequestParam MultipartFile