spring-framework / org.springframework.validation.beanvalidation

Package org.springframework.validation.beanvalidation

Types

BeanValidationPostProcessor

open class BeanValidationPostProcessor : BeanPostProcessor, InitializingBean

Simple BeanPostProcessor that checks JSR-303 constraint annotations in Spring-managed beans, throwing an initialization exception in case of constraint violations right before calling the bean's init method (if any).

CustomValidatorBean

open class CustomValidatorBean : SpringValidatorAdapter, Validator, InitializingBean

Configurable bean class that exposes a specific JSR-303 Validator through its original interface as well as through the Spring org.springframework.validation.Validator interface.

LocalValidatorFactoryBean

open class LocalValidatorFactoryBean : SpringValidatorAdapter, ValidatorFactory, ApplicationContextAware, InitializingBean, DisposableBean

This is the central class for javax.validation (JSR-303) setup in a Spring application context: It bootstraps a javax.validation.ValidationFactory and exposes it through the Spring org.springframework.validation.Validator interface as well as through the JSR-303 javax.validation.Validator interface and the javax.validation.ValidatorFactory interface itself.

When talking to an instance of this bean through the Spring or JSR-303 Validator interfaces, you'll be talking to the default Validator of the underlying ValidatorFactory. This is very convenient in that you don't have to perform yet another call on the factory, assuming that you will almost always use the default Validator anyway. This can also be injected directly into any target dependency of type org.springframework.validation.Validator!

As of Spring 5.0, this class requires Bean Validation 1.1+, with special support for Hibernate Validator 5.x (see #setValidationMessageSource). This class is also runtime-compatible with Bean Validation 2.0 and Hibernate Validator 6.0, with one special note: If you'd like to call BV 2.0's getClockProvider() method, obtain the native ValidatorFactory through #unwrap(ValidatorFactory.class) and call the getClockProvider() method on the returned native reference there.

This class is also being used by Spring's MVC configuration namespace, in case of the javax.validation API being present but no explicit Validator having been configured.

LocaleContextMessageInterpolator

open class LocaleContextMessageInterpolator : MessageInterpolator

Delegates to a target MessageInterpolator implementation but enforces Spring's managed Locale. Typically used to wrap the validation provider's default interpolator.

MessageSourceResourceBundleLocator

open class MessageSourceResourceBundleLocator : ResourceBundleLocator

Implementation of Hibernate Validator 4.3/5.x's ResourceBundleLocator interface, exposing a Spring MessageSource as localized MessageSourceResourceBundle.

MethodValidationInterceptor

open class MethodValidationInterceptor : MethodInterceptor

An AOP Alliance MethodInterceptor 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)

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.

As of Spring 5.0, this functionality requires a Bean Validation 1.1 provider.

MethodValidationPostProcessor

open class MethodValidationPostProcessor : AbstractBeanFactoryAwareAdvisingPostProcessor, InitializingBean

A convenient 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) 

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.

OptionalValidatorFactoryBean

open class OptionalValidatorFactoryBean : LocalValidatorFactoryBean

LocalValidatorFactoryBean subclass that simply turns org.springframework.validation.Validator calls into no-ops in case of no Bean Validation provider being available.

This is the actual class used by Spring's MVC configuration namespace, in case of the javax.validation API being present but no explicit Validator having been configured.

SpringConstraintValidatorFactory

open class SpringConstraintValidatorFactory : ConstraintValidatorFactory

JSR-303 ConstraintValidatorFactory implementation that delegates to a Spring BeanFactory for creating autowired ConstraintValidator instances.

Note that this class is meant for programmatic use, not for declarative use in a standard validation.xml file. Consider org.springframework.web.bind.support.SpringWebConstraintValidatorFactory for declarative use in a web application, e.g. with JAX-RS or JAX-WS.