Могу ли я создать клиент Spring Feign с параметрами Multipart?

Я получаю сообщение об ошибке: «Метод имеет слишком много параметров тела» при попытке создать клиент 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 Client


person cerebrotecnologico    schedule 09.05.2016    source источник
comment
Не сейчас, нет.   -  person spencergibb    schedule 09.05.2016


Ответы (1)


Теперь это должно быть возможно. Добавьте следующие зависимости:

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

Пример взят из: feign-form документы

person Dirk    schedule 07.07.2017