BeanPostProcessor implementation that delegates to a
JSR-303 provider for performing method-level validation on annotated methods.
Applicable methods have JSR-303 constraint annotations on their parameters and/or on their return value (in the latter case specified at the method level, typically as inline annotation), e.g.:
public @NotNull Object myValidMethod(@NotNull String arg1, @Max(10) int arg2)
In case of validation errors, the interceptor can raise
ConstraintViolationException, or adapt the violations to
MethodValidationResult and raise MethodValidationException.
Target classes with such annotated methods need to be annotated with Spring's
Validated annotation at the type level, for their methods to be searched for
inline constraint annotations. Validation groups can be specified through @Validated
as well. By default, JSR-303 will validate against its default group only.
As of Spring 5.0, this functionality requires a Bean Validation 1.1+ provider.
MethodValidationInterceptor, jakarta.validation.executable.ExecutableValidator
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private Class | |
| private Supplier |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| protected Advice | Returns: the interceptor to use (typically, but not necessarily, aMethodValidationInterceptor or subclass thereof)a Supplier for the Validator to use validator)Create AOP advice for method validation purposes, to be applied with a pointcut for the specified 'validated' annotation. |
| public void | setAdaptConstraintViolations(boolean adaptViolations)
Whether to adapt |
| public void | setValidatedAnnotationType(Class<? extends Annotation>
the desired annotation type validatedAnnotationType)Set the 'validated' annotation type. |
| public void | |
| public void | setValidatorFactory(ValidatorFactory validatorFactory)
Set the JSR-303 ValidatorFactory to delegate to for validating methods, using its default Validator. |
| public void | setValidatorProvider(ObjectProvider<Validator> validatorProvider)
Set a lazily initialized Validator to delegate to for validating methods. |
| adaptConstraintViolations | back to summary |
|---|---|
| private boolean adaptConstraintViolations | |
| validatedAnnotationType | back to summary |
|---|---|
| private Class<? extends Annotation> validatedAnnotationType | |
| validator | back to summary |
|---|---|
| private Supplier<Validator> validator | |
| MethodValidationPostProcessor | back to summary |
|---|---|
| public MethodValidationPostProcessor() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
| |
| createMethodValidationAdvice | back to summary |
|---|---|
| protected Advice createMethodValidationAdvice(Supplier<Validator> validator) Create AOP advice for method validation purposes, to be applied with a pointcut for the specified 'validated' annotation.
| |
| setAdaptConstraintViolations | back to summary |
|---|---|
| public void setAdaptConstraintViolations(boolean adaptViolations) Whether to adapt By default
| |
| setValidatedAnnotationType | back to summary |
|---|---|
| public void setValidatedAnnotationType(Class<? extends Annotation> validatedAnnotationType) Set the 'validated' annotation type.
The default validated annotation type is the This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a class is supposed to be validated in the sense of applying method validation.
| |
| setValidator | back to summary |
|---|---|
| public void setValidator(Validator validator) Set the JSR-303 Validator to delegate to for validating methods. Default is the default ValidatorFactory's default Validator. | |
| setValidatorFactory | back to summary |
|---|---|
| public void setValidatorFactory(ValidatorFactory validatorFactory) Set the JSR-303 ValidatorFactory to delegate to for validating methods, using its default Validator. Default is the default ValidatorFactory's default Validator. | |
| setValidatorProvider | back to summary |
|---|---|
| public void setValidatorProvider(ObjectProvider<Validator> validatorProvider) Set a lazily initialized Validator to delegate to for validating methods.
| |