0

I try to define multiple params in form-data with spring openfeign

 <dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

(version 2.1.9.RELEASE)

here is the method

@PostMapping(value = "/endpoint", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Result test(
    @Param("file") MultipartFile file,
    @Param("contraints") List<String> contraints);

but I get the following exception when starting service :

Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract (org.springframework.web.multipart.MultipartFile,java.util.List)
at feign.Util.checkState(Util.java:130) ~[feign-core-10.4.0.jar:?]

1 Answers1

0

Mixing Feign and Spring annotations will cause the issue.

Make sure you are using openfeign library @Param, not the spring query @Param and it's better to use @RequestParam instead of @param

For file, it's recommended to use @RequestPart instead of @Param

@PostMapping(value = {"/endpoint"}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Headers("Content-Type: multipart/form-data")
public Result test(@RequestPart("file") MultipartFile file);
Thirumal
  • 8,280
  • 11
  • 53
  • 103