-
Notifications
You must be signed in to change notification settings - Fork 814
Description
Hello. I saw a lot of similar issues, but looks like the problem is not resolved. I'm using Spring Boot 2.7.3 and Spring Cloud 2021.0.4 and getting startup error Method has too many Body parameters. In my project I have an external library (I can't modify it) that declares REST API interface using Spring Web annotations:
@PostMapping("/list")
Page<String> listElements(Pageable pageable, @RequestBody(required = false) String body);
When I try to create Feign client for it I'm getting error that I mentioned earlier. I start debugging the code and figured out that it does not matter either PageableSpringEncoder or PageableSpringQueryMapEncoder are registered or not - the code will fail earlier, even before those encoders take in place. So, the problem is that Pageable does not handled anyhow in "initialization" phase and is counted as a body and then, when method parser shifts to next method argument, it finds real "body" argument and fails, thinking that there are 2 bodies.
Want to pay attention, that this guide does not help. Furthermore, looks like this will not work for Spring MVC, because actually Spring awaits multiple sort query parameters for multi-sort request, instead of single comma-separated parameter.
I was managed to find workaround for that by creating next class and registering it instead of original SpringMvcContract:
public class SpringMvcContractFixed extends SpringMvcContract {
public SpringMvcContractFixed(List<AnnotatedParameterProcessor> annotatedParameterProcessors, ConversionService conversionService, boolean decodeSlash) {
super(annotatedParameterProcessors, conversionService, decodeSlash);
}
@Override
protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[] annotations, int paramIndex) {
if (data.method().getParameterTypes()[paramIndex].isAssignableFrom(Pageable.class)) {
data.queryMapIndex(paramIndex);
return false;
}
return super.processAnnotationsOnParameter(data, annotations, paramIndex);
}
}
But this does not looks good for me, because this solution tricks Feign and make him think that Pageable is a SpringQueryMap.
Any ideas how to resolve the problem in nice way?
Here is example project to reproduce this problem, just run DemoApplicationTests JUnit test.