Iam尝试使用feign客户端上传Multipart文件对象数组。
这是我尝试使用Feign客户端调用的服务。
public ResponseEntity<Object> manageFileUpload(@RequestParam("files")
MultipartFile[] files)
我尝试过使用,
My Feign客户端注释,
@FeignClient(value = "UPLOADUTILITIES", configuration =
Upload.MultipartSupportConfig.class, fallback =
UploadFallback.class)
My Method,
@RequestMapping(name = "upload", value = "/object", method =
RequestMethod.POST)
@Headers("Content-Type: multipart/form-data")
ResponseEntity<Object> manageFileUpload(@Param("files") MultipartFile[]
files);
我得到了错误的回报,
"message": "Type definition error: [simple type, class java.io.FileDescriptor]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile[0]->org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile[\"inputStream\"]->java.io.FileInputStream[\"fd\"])",
然后通过参考链接,
https://github.com/OpenFeign/feign-form#spring-multipartfile-and-spring-
cloud-netflix-feignclient-support
我在客户端尝试了打击代码。
public class MultipartSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
然后通过代码示例,我将我的MultiPart File对象更改为File Object。
现在我的请求被解雇了,但我得到的不是多部分请求。
我试过这个https://github.com/pcan/feign-client-test#feign-client-test,
我创建了一个类并使用了编码器类,并将我的编码器改为FeignSpringFormEncoder,
仍然没有找到序列化程序错误。
任何人都可以使用feign cleint共享一个简单的客户端,服务器示例,其中包含Array of Multipart文件请求。谢谢!