Class MethodValidationInterceptor
- All Implemented Interfaces:
 org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor
MethodInterceptor implementation that delegates to a
JSR-303 provider for performing method-level validation on annotated methods.
Applicable methods have Constraint annotations on
their parameters and/or on their return value (in the latter case specified at
the method level, typically as inline annotation).
For example: 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.
Validation groups can be specified through Spring's Validated annotation
at the type level of the containing target class, applying to all public service methods
of that class. By default, JSR-303 will validate against its default group only.
- Since:
 - 3.1
 - Author:
 - Juergen Hoeller, Rossen Stoyanchev
 - See Also:
 
- 
Constructor Summary
ConstructorsConstructorDescriptionCreate a new MethodValidationInterceptor using a default JSR-303 validator underneath.MethodValidationInterceptor(jakarta.validation.Validator validator) Create a new MethodValidationInterceptor using the given JSR-303 Validator.MethodValidationInterceptor(jakarta.validation.ValidatorFactory validatorFactory) Create a new MethodValidationInterceptor using the given JSR-303 ValidatorFactory.MethodValidationInterceptor(Supplier<jakarta.validation.Validator> validator) Create a new MethodValidationInterceptor for the supplied (potentially lazily initialized) Validator.MethodValidationInterceptor(Supplier<jakarta.validation.Validator> validator, boolean adaptViolations) Create a new MethodValidationInterceptor for the supplied (potentially lazily initialized) Validator. - 
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?>[]determineValidationGroups(org.aopalliance.intercept.MethodInvocation invocation) Determine the validation groups to validate against for the given method invocation.invoke(org.aopalliance.intercept.MethodInvocation invocation)  
- 
Constructor Details
- 
MethodValidationInterceptor
public MethodValidationInterceptor()Create a new MethodValidationInterceptor using a default JSR-303 validator underneath. - 
MethodValidationInterceptor
public MethodValidationInterceptor(jakarta.validation.ValidatorFactory validatorFactory) Create a new MethodValidationInterceptor using the given JSR-303 ValidatorFactory.- Parameters:
 validatorFactory- the JSR-303 ValidatorFactory to use
 - 
MethodValidationInterceptor
public MethodValidationInterceptor(jakarta.validation.Validator validator) Create a new MethodValidationInterceptor using the given JSR-303 Validator.- Parameters:
 validator- the JSR-303 Validator to use
 - 
MethodValidationInterceptor
Create a new MethodValidationInterceptor for the supplied (potentially lazily initialized) Validator.- Parameters:
 validator- a Supplier for the Validator to use- Since:
 - 6.0
 
 - 
MethodValidationInterceptor
public MethodValidationInterceptor(Supplier<jakarta.validation.Validator> validator, boolean adaptViolations) Create a new MethodValidationInterceptor for the supplied (potentially lazily initialized) Validator.- Parameters:
 validator- a Supplier for the Validator to useadaptViolations- whether to adaptConstraintViolations, and iftrue, raiseMethodValidationException, of iffalseraiseConstraintViolationExceptioninstead- Since:
 - 6.1
 
 
 - 
 - 
Method Details
- 
invoke
 - 
determineValidationGroups
protected Class<?>[] determineValidationGroups(org.aopalliance.intercept.MethodInvocation invocation) Determine the validation groups to validate against for the given method invocation.Default are the validation groups as specified in the
Validatedannotation on the method, or on the containing target class of the method, or for an AOP proxy without a target (with all behavior in advisors), also check on proxied interfaces.- Parameters:
 invocation- the current MethodInvocation- Returns:
 - the applicable validation groups as a Class array
 
 
 -