我可以使用 Multipart 参数生成 Spring Feign 客户端吗? [英] Can I generate a Spring Feign client with Multipart parameters?
本文介绍了我可以使用 Multipart 参数生成 Spring Feign 客户端吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误:方法有太多的身体参数"尝试生成 Spring Feign 客户端时
I am getting the error: "Method has too many Body parameters" when trying to generate a Spring Feign client
@RequestMapping(value="/media", method=RequestMethod.POST)
String uploadMedia(@RequestHeader("Authentication") String token,
@RequestPart("media") MultipartFile audio,
@RequestPart("a-json-object") SomeClass someClazz,
@RequestPart("another-json-object") AnotherClass anotherClazz);
我找到了以下解决方案,它在使用常规 Feign 注释时有效,但不适用于 Spring MVC 注释:
I found the following solution, which works when using regular Feign annotations, but not with Spring MVC annotations:
推荐答案
现在应该可以了.添加以下依赖项:
It should be possible now. Add the following dependencies:
<dependencies>
...
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>2.2.0</version>
</dependency>
...
并使用此客户端配置:
@FeignClient(name = "file-upload-service", configuration = FileUploadServiceClient.MultipartSupportConfig.class)
public interface FileUploadServiceClient extends IFileUploadServiceClient {
@Configuration
public class MultipartSupportConfig {
@Bean
@Primary
@Scope("prototype")
public Encoder feignFormEncoder() {
return new SpringFormEncoder();
}
}
}
示例取自:伪装形式的文档
这篇关于我可以使用 Multipart 参数生成 Spring Feign 客户端吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文