spring-framework / org.springframework.validation.beanvalidation / LocalValidatorFactoryBean / <init>

<init>

LocalValidatorFactoryBean()

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.

Author
Juergen Hoeller

Since
3.0

See Also
javax.validation.ValidatorFactoryjavax.validation.Validatorjavax.validation.Validation#buildDefaultValidatorFactory()javax.validation.ValidatorFactory#getValidator()