类 LocalValidatorFactoryBean
- 所有已实现的接口:
Aware,DisposableBean,InitializingBean,ApplicationContextAware,SmartValidator,Validator,jakarta.validation.Validator,jakarta.validation.ValidatorFactory,AutoCloseable
- 直接已知子类:
OptionalValidatorFactoryBean
jakarta.validation (JSR-303) setup in a Framework
application context: It bootstraps a jakarta.validation.ValidationFactory and
exposes it through the Framework 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 Framework 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!
This class is also being used by Framework's MVC configuration namespace, in case of the
jakarta.validation API being present but no explicit Validator having been configured.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller
- 另请参阅:
-
ValidatorFactoryValidatorValidation.buildDefaultValidatorFactory()ValidatorFactory.getValidator()
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidvoidclose()voiddestroy()jakarta.validation.ClockProviderjakarta.validation.ConstraintValidatorFactoryjakarta.validation.MessageInterpolatorjakarta.validation.ParameterNameProviderjakarta.validation.TraversableResolverAllow Map access to the bean validation properties to be passed to the validation provider, with the option to add or override specific entries.jakarta.validation.Validatorprotected voidpostProcessConfiguration(jakarta.validation.Configuration<?> configuration) Post-process the given Bean Validation configuration, adding to or overriding any of its settings.voidsetApplicationContext(ApplicationContext applicationContext) Set the ApplicationContext that this object runs in.voidsetConfigurationInitializer(Consumer<jakarta.validation.Configuration<?>> configurationInitializer) Specify a callback for customizing the Bean ValidationConfigurationinstance, as an alternative to overriding thepostProcessConfiguration(Configuration)method in customLocalValidatorFactoryBeansubclasses.voidsetConstraintValidatorFactory(jakarta.validation.ConstraintValidatorFactory constraintValidatorFactory) Specify a custom ConstraintValidatorFactory to use for this ValidatorFactory.voidsetMappingLocations(cn.taketoday.core.io.Resource... mappingLocations) Specify resource locations to load XML constraint mapping files from, if any.voidsetMessageInterpolator(jakarta.validation.MessageInterpolator messageInterpolator) Specify a custom MessageInterpolator to use for this ValidatorFactory and its exposed default Validator.voidsetParameterNameDiscoverer(cn.taketoday.core.ParameterNameDiscoverer parameterNameDiscoverer) Set the ParameterNameDiscoverer to use for resolving method and constructor parameter names if needed for message interpolation.voidsetProviderClass(Class providerClass) Specify the desired provider class, if any.voidsetTraversableResolver(jakarta.validation.TraversableResolver traversableResolver) Specify a custom TraversableResolver to use for this ValidatorFactory and its exposed default Validator.voidsetValidationMessageSource(MessageSource messageSource) Specify a custom Framework MessageSource for resolving validation messages, instead of relying on JSR-303's default "ValidationMessages.properties" bundle in the classpath.voidsetValidationProperties(Properties jpaProperties) Specify bean validation properties to be passed to the validation provider.voidsetValidationPropertyMap(Map<String, String> validationProperties) Specify bean validation properties to be passed to the validation provider as a Map.voidsetValidationProviderResolver(jakarta.validation.ValidationProviderResolver validationProviderResolver) Specify a JSR-303ValidationProviderResolverfor bootstrapping the provider of choice, as an alternative toMETA-INFdriven resolution.<T> Tjakarta.validation.ValidatorContext从类继承的方法 cn.taketoday.validation.beanvalidation.InfraValidatorAdapter
determineErrorCode, determineField, forExecutables, getArgumentsForConstraint, getConstraintsForClass, getRejectedValue, getResolvableField, processConstraintViolations, requiresMessageFormat, supports, validate, validate, validate, validateProperty, validateValue, validateValue
-
构造器详细资料
-
LocalValidatorFactoryBean
public LocalValidatorFactoryBean()
-
-
方法详细资料
-
setProviderClass
Specify the desired provider class, if any.If not specified, JSR-303's default search mechanism will be used.
- 另请参阅:
-
Validation.byProvider(Class)Validation.byDefaultProvider()
-
setValidationProviderResolver
public void setValidationProviderResolver(jakarta.validation.ValidationProviderResolver validationProviderResolver) Specify a JSR-303ValidationProviderResolverfor bootstrapping the provider of choice, as an alternative toMETA-INFdriven resolution. -
setMessageInterpolator
public void setMessageInterpolator(@Nullable jakarta.validation.MessageInterpolator messageInterpolator) Specify a custom MessageInterpolator to use for this ValidatorFactory and its exposed default Validator. -
setValidationMessageSource
Specify a custom Framework MessageSource for resolving validation messages, instead of relying on JSR-303's default "ValidationMessages.properties" bundle in the classpath. This may refer to a Framework 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
ResourceBundleMessageInterpolatorclass 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'sResourceBundleMessageInterpolatorand passing in a Framework-basedResourceBundleLocatorwhen constructing your interpolator.In order for Hibernate's default validation messages to be resolved still, your
MessageSourcemust be configured for optional resolution (usually the default). In particular, theMessageSourceinstance specified here should not apply"useCodeAsDefaultMessage"behavior. Please double-check your setup accordingly.- 另请参阅:
-
ResourceBundleMessageInterpolator
-
setTraversableResolver
public void setTraversableResolver(@Nullable jakarta.validation.TraversableResolver traversableResolver) Specify a custom TraversableResolver to use for this ValidatorFactory and its exposed default Validator. -
setConstraintValidatorFactory
public void setConstraintValidatorFactory(@Nullable jakarta.validation.ConstraintValidatorFactory constraintValidatorFactory) Specify a custom ConstraintValidatorFactory to use for this ValidatorFactory.Default is a
ContextConstraintValidatorFactory, delegating to the containing ApplicationContext for creating autowired ConstraintValidator instances. -
setParameterNameDiscoverer
public void setParameterNameDiscoverer(@Nullable cn.taketoday.core.ParameterNameDiscoverer parameterNameDiscoverer) Set the ParameterNameDiscoverer to use for resolving method and constructor parameter names if needed for message interpolation.Default is a
DefaultParameterNameDiscoverer. -
setMappingLocations
public void setMappingLocations(cn.taketoday.core.io.Resource... mappingLocations) Specify resource locations to load XML constraint mapping files from, if any. -
setValidationProperties
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.
- 另请参阅:
-
Configuration.addProperty(String, String)
-
setValidationPropertyMap
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.
- 另请参阅:
-
Configuration.addProperty(String, String)
-
getValidationPropertyMap
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]".
-
setConfigurationInitializer
public void setConfigurationInitializer(Consumer<jakarta.validation.Configuration<?>> configurationInitializer) Specify a callback for customizing the Bean ValidationConfigurationinstance, as an alternative to overriding thepostProcessConfiguration(Configuration)method in customLocalValidatorFactoryBeansubclasses.This enables convenient customizations for application purposes. Infrastructure extensions may keep overriding the
postProcessConfiguration(jakarta.validation.Configuration<?>)template method. -
setApplicationContext
从接口复制的说明:ApplicationContextAwareSet the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.Invoked after population of normal bean properties but before an init callback such as
InitializingBean.afterPropertiesSet()or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(cn.taketoday.core.io.ResourceLoader),ApplicationEventPublisherAware.setApplicationEventPublisher(cn.taketoday.context.ApplicationEventPublisher)andMessageSourceAware, if applicable.- 指定者:
setApplicationContext在接口中ApplicationContextAware- 参数:
applicationContext- the ApplicationContext object to be used by this object- 另请参阅:
-
afterPropertiesSet
public void afterPropertiesSet()- 指定者:
afterPropertiesSet在接口中InitializingBean
-
postProcessConfiguration
protected void postProcessConfiguration(jakarta.validation.Configuration<?> configuration) Post-process the given Bean Validation configuration, adding to or overriding any of its settings.Invoked right before building the
ValidatorFactory.- 参数:
configuration- the Configuration object, pre-populated with settings driven by LocalValidatorFactoryBean's properties
-
getValidator
public jakarta.validation.Validator getValidator()- 指定者:
getValidator在接口中jakarta.validation.ValidatorFactory
-
usingContext
public jakarta.validation.ValidatorContext usingContext()- 指定者:
usingContext在接口中jakarta.validation.ValidatorFactory
-
getMessageInterpolator
public jakarta.validation.MessageInterpolator getMessageInterpolator()- 指定者:
getMessageInterpolator在接口中jakarta.validation.ValidatorFactory
-
getTraversableResolver
public jakarta.validation.TraversableResolver getTraversableResolver()- 指定者:
getTraversableResolver在接口中jakarta.validation.ValidatorFactory
-
getConstraintValidatorFactory
public jakarta.validation.ConstraintValidatorFactory getConstraintValidatorFactory()- 指定者:
getConstraintValidatorFactory在接口中jakarta.validation.ValidatorFactory
-
getParameterNameProvider
public jakarta.validation.ParameterNameProvider getParameterNameProvider()- 指定者:
getParameterNameProvider在接口中jakarta.validation.ValidatorFactory
-
getClockProvider
public jakarta.validation.ClockProvider getClockProvider()- 指定者:
getClockProvider在接口中jakarta.validation.ValidatorFactory
-
unwrap
- 指定者:
unwrap在接口中jakarta.validation.Validator- 指定者:
unwrap在接口中jakarta.validation.ValidatorFactory- 覆盖:
unwrap在类中InfraValidatorAdapter
-
close
public void close()- 指定者:
close在接口中AutoCloseable- 指定者:
close在接口中jakarta.validation.ValidatorFactory
-
destroy
public void destroy()- 指定者:
destroy在接口中DisposableBean
-