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.
Author
Juergen Hoeller
Since
3.0
See Also
javax.validation.ValidatorFactoryjavax.validation.Validatorjavax.validation.Validation#buildDefaultValidatorFactory()javax.validation.ValidatorFactory#getValidator()
LocalValidatorFactoryBean()
This is the central class for 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 This class is also being used by Spring's MVC configuration namespace, in case of the |
open fun afterPropertiesSet(): Unit |
|
open fun close(): Unit |
|
open fun destroy(): Unit |
|
open fun getConstraintValidatorFactory(): ConstraintValidatorFactory |
|
open fun getMessageInterpolator(): MessageInterpolator |
|
open fun getParameterNameProvider(): ParameterNameProvider |
|
open fun getTraversableResolver(): TraversableResolver |
|
open fun getValidationPropertyMap(): MutableMap<String, String>
Allow Map access to the bean validation properties to be passed to the validation provider, with the option to add or override specific entries. Useful for specifying entries directly, for example via "validationPropertyMap[myKey]". |
|
open fun getValidator(): Validator |
|
open fun setApplicationContext(applicationContext: ApplicationContext): Unit |
|
open fun setConstraintValidatorFactory(constraintValidatorFactory: ConstraintValidatorFactory): Unit
Specify a custom ConstraintValidatorFactory to use for this ValidatorFactory. Default is a SpringConstraintValidatorFactory, delegating to the containing ApplicationContext for creating autowired ConstraintValidator instances. |
|
open fun setMappingLocations(vararg mappingLocations: Resource): Unit
Specify resource locations to load XML constraint mapping files from, if any. |
|
open fun setMessageInterpolator(messageInterpolator: MessageInterpolator): Unit
Specify a custom MessageInterpolator to use for this ValidatorFactory and its exposed default Validator. |
|
open fun setParameterNameDiscoverer(parameterNameDiscoverer: ParameterNameDiscoverer): Unit
Set the ParameterNameDiscoverer to use for resolving method and constructor parameter names if needed for message interpolation. Default is a org.springframework.core.DefaultParameterNameDiscoverer. |
|
open fun setProviderClass(providerClass: Class<Any>): Unit
Specify the desired provider class, if any. If not specified, JSR-303's default search mechanism will be used. |
|
open fun setTraversableResolver(traversableResolver: TraversableResolver): Unit
Specify a custom TraversableResolver to use for this ValidatorFactory and its exposed default Validator. |
|
open fun setValidationMessageSource(messageSource: MessageSource): Unit
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 |
|
open fun setValidationProperties(jpaProperties: Properties): Unit
Specify bean validation properties to be passed to the validation provider. Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions. |
|
open fun setValidationPropertyMap(validationProperties: MutableMap<String, String>): Unit
Specify bean validation properties to be passed to the validation provider as a Map. Can be populated with a "map" or "props" element in XML bean definitions. |
|
open fun setValidationProviderResolver(validationProviderResolver: ValidationProviderResolver): Unit
Specify a JSR-303 ValidationProviderResolver for bootstrapping the provider of choice, as an alternative to |
|
open fun <T : Any> unwrap(type: Class<T>): T |
|
open fun usingContext(): ValidatorContext |
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 |