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 Validator interface
as well as through the JSR-303 Validator interface and the
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 Validator!
As of Spring 5.0, this class requires Bean Validation 1.1+, with special support
for Hibernate Validator 5.x (see setValidationMessageSource(org.springframework.context.MessageSource)).
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.
Specify a custom Spring MessageSource for resolving validation messages,
instead of relying on JSR-303's default "ValidationMessages.properties" bundle
in the classpath.
Specify a custom MessageInterpolator to use for this ValidatorFactory
and its exposed default Validator.
setValidationMessageSource
public void setValidationMessageSource(MessageSource messageSource)
Specify a custom Spring MessageSource for resolving validation messages,
instead of relying on JSR-303's default "ValidationMessages.properties" bundle
in the classpath. This may refer to a Spring context's shared "messageSource" bean,
or to some special MessageSource setup for validation purposes only.
NOTE: This feature requires Hibernate Validator 4.3 or higher on the classpath.
You may nevertheless use a different validation provider but Hibernate Validator's
ResourceBundleMessageInterpolator class must be accessible during configuration.
Specify either this property or "messageInterpolator",
not both. If you would like to build a custom MessageInterpolator, consider deriving from
Hibernate Validator's ResourceBundleMessageInterpolator and passing in a
Spring-based ResourceBundleLocator when constructing your interpolator.
In order for Hibernate's default validation messages to be resolved still, your
MessageSource must be configured for optional resolution (usually the default).
In particular, the MessageSource instance specified here should not apply
"useCodeAsDefaultMessage" behavior. Please double-check your setup accordingly.
Invoked by the containing BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall
configuration and final initialization when all bean properties have been set.