8

尝试生成 Spring Feign 客户端时出现错误:“方法有太多的正文参数”

@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 注释:

Feign 客户端上的“身体参数过多”异常

4

1 回答 1

4

现在应该可以了。添加以下依赖项:

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

示例取自:feign-form docs

于 2017-07-07T12:39:09.143 回答