Bean Validation 1.1 added a @javax.validation.executable.ValidateOnExecution annotation meant to mark classes or methods whose method executions should be validated. This is in some ways quite synonymous with Spring's @Validated, but with broader implications.
@Validated is for classes and parameters only. @ValidateOnExecution applies to packages, classes, methods, and constructors (but not parameters). So, even if I configured the MethodValidationPostProcessor to look for @ValidateOnExecution by calling setValidatedAnnotationType it wouldn't match cases where the package or method was annotated.
Out of the box, if a MethodValidationPostProcessor is defined it seems like Spring should enable method validation if any of the following conditions are met:
The package is annotated @Validatedor@ValidateOnExecution
The class is annotated @Validatedor@ValidateOnExecution
The constructor is annotated @Validatedor@ValidateOnExecution (assuming Spring is responsible for the instantiation of the bean)
The method is annotated @Validatedor@ValidateOnExecution
The parameter is annotated @Validated (to preserve current functionality)
This will necessitate:
Expanding the @Target of @Validated to include packages, constructors, and methods
Changing MethodPostProcessor to look for both annotations on the package, class, or method instead of just @Validated on the class
Changing bean instantiation procedures to look for both annotations on the constructor
Affects: 4.0 M1
#13812@Validated should allow ElementType.METHOD target
1 votes, 4 watchers
The text was updated successfully, but these errors were encountered:
What I don't know is whether a BV implementation like Hibernate Validator picks this up and uses it when Validator#validate is called. I think probably not. It should be tested, but assuming I'm right this change should be made as well.