Describe the bug Got the following error while starting the app:
Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: Body parameters cannot be used with form parameters.
Warnings:
-
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
org.springframework.cloud:spring-cloud-starter-openfeign:3.1.1
@FeignClient(name = "foo-service", path = "/user/{userId}")
public interface FooService {
@RequestMapping(value = "/foo", method = RequestMethod.POST)
void doFoo(@PathVariable Long userId, @RequestBody User user);
}
Works fine if there is no @RequestBody in the method.
Comment From: OlgaMaciaszek
The path variable segment should be defined at method level, like so:
@RequestMapping(value = "/foo/user/{userId}", method = RequestMethod.POST)
void doFoo(@PathVariable Long userId, @RequestBody String user);
As stated in the javadoc, the path attribute in @FeignClient allows to define a common path prefix for all the methods, but it does not support path variable resolution.