I would like to use validation groups in my service layer to validate dtos, but am not able to trigger validation exceptions when using @Validated on a method parameter. @Valid works, but to use groups I need @Validated to work. I have isolated the issue in a reproduction repo which includes these minimal classes:
thanks for getting back to me. I tried it with get as the annotation use site with the same result. Validation of method parameters does work, but only when the parameter is annotated with @Valid and not @Validated. In the replication project are some tests which demonstrate that.
Based on a discussion I had with Juergen Hoeller, @Validated can only be used at the class level or method level but not at the individual parameter level. Putting @Validated(MyGroup.class) at the method level and then @Valid at each parameter with nested properties is correct. Essentially, @Validated triggers a Bean Validation validate step. For MethodValidationPostProcessor, this is always for the entire method, i.e. all parameters in one step. whereas in MVC, we validate individual parameters, with other parameters of the same method completely unaffected.
As a consequence I think current behavior is correct.