Can I generate a Spring Feign client with Multipart parameters?

北城余情 提交于 2019-12-19 07:32:15

问题


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);

I found the following solution, which works when using regular Feign annotations, but not with Spring MVC annotations:

'Too many body parameters' Exception on Feign Client


回答1:


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>
...

and use this client configuration:

@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();
        }
    }
}

Example was taken from: feign-form docs



来源:https://stackoverflow.com/questions/37121424/can-i-generate-a-spring-feign-client-with-multipart-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!