org.springframework.validation.beanvalidation

## 类 LocalValidatorFactoryBean

- java.lang.Object
- - org.springframework.validation.beanvalidation.SpringValidatorAdapter
  - - org.springframework.validation.beanvalidation.LocalValidatorFactoryBean

- 所有已实现的接口:
    Validator, ValidatorFactory, org.springframework.beans.factory.Aware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, ApplicationContextAware, SmartValidator
  直接已知子类:
    OptionalValidatorFactoryBean

      public class LocalValidatorFactoryBean
      extends SpringValidatorAdapter
      implements ValidatorFactory, ApplicationContextAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.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 `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.

  从以下版本开始:
    3.0
  作者:
    Juergen Hoeller
  另请参阅:
    `ValidatorFactory`, `Validator`, `Validation.buildDefaultValidatorFactory()`, `ValidatorFactory.getValidator()`

- - ### 构造器概要

    构造器
    构造器和说明
    `LocalValidatorFactoryBean()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `afterPropertiesSet()`
    `void` | `close()`
    `void` | `destroy()`
    `ConstraintValidatorFactory` | `getConstraintValidatorFactory()`
    `MessageInterpolator` | `getMessageInterpolator()`
    `ParameterNameProvider` | `getParameterNameProvider()`
    `TraversableResolver` | `getTraversableResolver()`
    `Map<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.
    `Validator` | `getValidator()`
    `protected void` | `postProcessConfiguration(Configuration<?> configuration)` Post-process the given Bean Validation configuration, adding to or overriding any of its settings.
    `void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.
    `void` | `setConstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)` Specify a custom ConstraintValidatorFactory to use for this ValidatorFactory.
    `void` | `setMappingLocations(org.springframework.core.io.Resource... mappingLocations)` Specify resource locations to load XML constraint mapping files from, if any.
    `void` | `setMessageInterpolator(MessageInterpolator messageInterpolator)` Specify a custom MessageInterpolator to use for this ValidatorFactory and its exposed default Validator.
    `void` | `setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)` Set the ParameterNameDiscoverer to use for resolving method and constructor parameter names if needed for message interpolation.
    `void` | `setProviderClass(Class providerClass)` Specify the desired provider class, if any.
    `void` | `setTraversableResolver(TraversableResolver traversableResolver)` Specify a custom TraversableResolver to use for this ValidatorFactory and its exposed default Validator.
    `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.
    `void` | `setValidationProperties(Properties jpaProperties)` Specify bean validation properties to be passed to the validation provider.
    `void` | `setValidationPropertyMap(Map<String,String> validationProperties)` Specify bean validation properties to be passed to the validation provider as a Map.
    `void` | `setValidationProviderResolver(ValidationProviderResolver validationProviderResolver)` Specify a JSR-303 `ValidationProviderResolver` for bootstrapping the provider of choice, as an alternative to `META-INF` driven resolution.
    `<T> T` | `unwrap(Class<T> type)`
    `ValidatorContext` | `usingContext()`

    - ### 从类继承的方法 org.springframework.validation.beanvalidation.SpringValidatorAdapter

      `determineErrorCode, determineField, forExecutables, getArgumentsForConstraint, getConstraintsForClass, getRejectedValue, getResolvableField, processConstraintViolations, supports, validate, validate, validate, validateProperty, validateValue`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### LocalValidatorFactoryBean

          public LocalValidatorFactoryBean()

  - ### 方法详细资料

    - #### setProviderClass

          public void setProviderClass(Class providerClass)

      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(ValidationProviderResolver validationProviderResolver)

      Specify a JSR-303 `ValidationProviderResolver` for bootstrapping the provider of choice, as an alternative to `META-INF` driven resolution.
      从以下版本开始:
        4.3

    - #### setMessageInterpolator

          public void setMessageInterpolator(MessageInterpolator messageInterpolator)

      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.

      另请参阅:
        `ResourceBundleMessageInterpolator`

    - #### setTraversableResolver

          public void setTraversableResolver(TraversableResolver traversableResolver)

      Specify a custom TraversableResolver to use for this ValidatorFactory and its exposed default Validator.

    - #### setConstraintValidatorFactory

          public void setConstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)

      Specify a custom ConstraintValidatorFactory to use for this ValidatorFactory.

      Default is a `SpringConstraintValidatorFactory`, delegating to the containing ApplicationContext for creating autowired ConstraintValidator instances.

    - #### setParameterNameDiscoverer

          public void setParameterNameDiscoverer(org.springframework.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(org.springframework.core.io.Resource... mappingLocations)

      Specify resource locations to load XML constraint mapping files from, if any.

    - #### setValidationProperties

          public void setValidationProperties(Properties jpaProperties)

      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

          public void setValidationPropertyMap(@Nullable
                                               Map<String,String> validationProperties)

      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

          public Map<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]".

    - #### setApplicationContext

          public void setApplicationContext(ApplicationContext applicationContext)

      从接口复制的说明: `ApplicationContextAware`
      Set 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 after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

      指定者:
        `setApplicationContext` 在接口中 `ApplicationContextAware`
      参数:
        `applicationContext` - the ApplicationContext object to be used by this object
      另请参阅:
        `BeanInitializationException`

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      指定者:
        `afterPropertiesSet` 在接口中 `org.springframework.beans.factory.InitializingBean`

    - #### postProcessConfiguration

          protected void postProcessConfiguration(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 Validator getValidator()

      指定者:
        `getValidator` 在接口中 `ValidatorFactory`

    - #### usingContext

          public ValidatorContext usingContext()

      指定者:
        `usingContext` 在接口中 `ValidatorFactory`

    - #### getMessageInterpolator

          public MessageInterpolator getMessageInterpolator()

      指定者:
        `getMessageInterpolator` 在接口中 `ValidatorFactory`

    - #### getTraversableResolver

          public TraversableResolver getTraversableResolver()

      指定者:
        `getTraversableResolver` 在接口中 `ValidatorFactory`

    - #### getConstraintValidatorFactory

          public ConstraintValidatorFactory getConstraintValidatorFactory()

      指定者:
        `getConstraintValidatorFactory` 在接口中 `ValidatorFactory`

    - #### getParameterNameProvider

          public ParameterNameProvider getParameterNameProvider()

      指定者:
        `getParameterNameProvider` 在接口中 `ValidatorFactory`

    - #### unwrap

          public <T> T unwrap(@Nullable
                              Class<T> type)

      指定者:
        `unwrap` 在接口中 `Validator`
      指定者:
        `unwrap` 在接口中 `ValidatorFactory`
      覆盖:
        `unwrap` 在类中 `SpringValidatorAdapter`

    - #### close

          public void close()

      指定者:
        `close` 在接口中 `ValidatorFactory`

    - #### destroy

          public void destroy()

      指定者:
        `destroy` 在接口中 `org.springframework.beans.factory.DisposableBean`