I'm learning to use Spring's Feign Client, so I've built two simple projects (serviceA and serviceB) to test it out. I have the following code:
serviceA rest interface:
@RequestMapping("/users")
public interface UserRest {
@PostMapping
public ResponseEntity<User> createUser(@Valid @RequestBody User user, BindingResult br);
}
serviceA rest interface implementation:
@RestController
public class UserController implements UserRest {
@Override
@PostMapping
public ResponseEntity<User> createUser(@Valid @RequestBody User user, BindingResult br) {
// validate user
// persist user
return ResponseEntity.ok(user);
}
}
serviceA feign client declaration:
@FeignClient(value = "serviceA", decode404 = true)
public interface UserFeignClient extends UserRest {}
Now when I autowire an instance of UserFeignClient
into my serviceB, I can use it just fine when my REST methods take a single parameter. However, when I then try to validate the parameter using BindingResult
like above, I get the following exception:
java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.http.ResponseEntity com.mypackage.servicea.api.UserRest.createUser(org.apache.catalina.User,org.springframework.validation.BindingResult)
Why does Feign think the BindingResult is a second Body entity? Is there any way to fix this?