There are three ways to bootstrap it:
ValidatorFactory.
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();In this case, the default validation provider resolver will be used to locate available providers.
The chosen provider is defined as followed:
ValidationProviderResolver instance is used.ValidationProviderResolver. The chosen
ValidationProvider is then determined in the same way
as in the default bootstrapping case (see above).
Configuration<?> configuration = Validation .byDefaultProvider() .providerResolver( new MyResolverStrategy() ) .configure(); ValidatorFactory factory = configuration.buildValidatorFactory();
Optionally you can choose a custom ValidationProviderResolver.
ACMEConfiguration configuration = Validation .byProvider(ACMEProvider.class) .providerResolver( new MyResolverStrategy() ) // optionally set the provider resolver .configure(); ValidatorFactory factory = configuration.buildValidatorFactory();
Note:
ValidatorFactory object built by the bootstrap process should be cached
and shared amongst Validator consumers.
| Modifier and Type | Class and Description |
|---|---|
| private static class | Validation.DefaultValidationProviderResolver
Finds |
| private static class | |
| private static class | |
| private static class | |
| private static class | Validation.ProviderSpecificBootstrapImpl<T extends Configuration
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static ValidatorFactory | Returns: ValidatorFactory instanceBuilds and returns a |
| public static GenericBootstrap | Returns: instance building a genericConfiguration
compliant with the bootstrap state providedBuilds a |
| public static < the type of the T extends ConfigurationConfiguration corresponding to this
ValidationProviderthe type of the U extends ValidationProviderValidationProvider implementation | Returns: instance building a provider specificConfiguration
sub interface implementationthe providerType)ValidationProvider implementation typeBuilds a |
| private static void | clearDefaultValidationProviderResolverCache()
Not a public API; it can be used reflectively by code that integrates with Jakarta Bean Validation, e.g. application servers, to clear the provider cache maintained by the default provider resolver. |
| Validation | back to summary |
|---|---|
| public Validation() | |
| buildDefaultValidatorFactory | back to summary |
|---|---|
| public static ValidatorFactory buildDefaultValidatorFactory() Builds and returns a The provider list is resolved using the default validation provider resolver logic.
The code is semantically equivalent to
| |
| byDefaultProvider | back to summary |
|---|---|
| public static GenericBootstrap byDefaultProvider() Builds a Configuration<?> configuration = Validation .byDefaultProvider() .providerResolver( new MyResolverStrategy() ) .configure(); ValidatorFactory factory = configuration.buildValidatorFactory();The provider can be specified in the XML configuration. If the XML configuration does not exist or if no provider is specified, the first available provider will be returned.
| |
| byProvider | back to summary |
|---|---|
| public static <T extends Configuration Builds a Optionally overrides the provider resolution strategy used to determine the provider. Used by applications targeting a specific provider programmatically.
ACMEConfiguration configuration =
Validation.byProvider(ACMEProvider.class)
.providerResolver( new MyResolverStrategy() )
.configure();
,
where ACMEConfiguration is the
Configuration sub interface uniquely identifying the
ACME Jakarta Bean Validation provider. and ACMEProvider is the
ValidationProvider implementation of the ACME provider.
| |
| clearDefaultValidationProviderResolverCache | back to summary |
|---|---|
| private static void clearDefaultValidationProviderResolverCache() Not a public API; it can be used reflectively by code that integrates with Jakarta Bean Validation, e.g. application servers, to clear the provider cache maintained by the default provider resolver. This is a strictly unsupported API, its definition may be changed or removed at any time. Its purpose is to explore the addition of standardized methods for dealing with provider caching in a future revision of the spec.
| |
ValidationProvider according to the default ValidationProviderResolver defined in the
Jakarta Bean Validation specification. This implementation first uses thread's context classloader to locate providers.
If no suitable provider is found using the aforementioned class loader, it uses current class loader.
If it still does not find any suitable provider, it tries to locate the built-in provider using the current
class loader.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public List | getValidationProviders()
Implements jakarta. ValidationProvider available in the runtime environment.
|
| DefaultValidationProviderResolver | back to summary |
|---|---|
| private DefaultValidationProviderResolver() | |
| getValidationProviders | back to summary |
|---|---|
| public List Implements jakarta. Doc from jakarta. Returns a list of
| |
| Modifier and Type | Field and Description |
|---|---|
| private ValidationProviderResolver | |
| private ValidationProviderResolver |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public Configuration | configure()
Implements jakarta. Configuration implementation.
|
| public ValidationProviderResolver | getDefaultValidationProviderResolver()
Implements jakarta. ValidationProviderResolver
strategy instance.
|
| public ValidationProviderResolver | getValidationProviderResolver()
Implements jakarta. ValidationProviderResolver strategy
instance or null if undefined.
|
| public GenericBootstrap | providerResolver(ValidationProviderResolver
the resolver)ValidationProviderResolver to use for bootstrappingImplements jakarta. |
| defaultResolver | back to summary |
|---|---|
| private ValidationProviderResolver defaultResolver | |
| resolver | back to summary |
|---|---|
| private ValidationProviderResolver resolver | |
| GenericBootstrapImpl | back to summary |
|---|---|
| private GenericBootstrapImpl() | |
| configure | back to summary |
|---|---|
| public Configuration Implements jakarta. Doc from jakarta. Returns a generic
The
| |
| getDefaultValidationProviderResolver | back to summary |
|---|---|
| public ValidationProviderResolver getDefaultValidationProviderResolver() Implements jakarta. Doc from jakarta. Specification default
| |
| getValidationProviderResolver | back to summary |
|---|---|
| public ValidationProviderResolver getValidationProviderResolver() Implements jakarta. Doc from jakarta. User defined
| |
| providerResolver | back to summary |
|---|---|
| public GenericBootstrap providerResolver(ValidationProviderResolver resolver) Implements jakarta. Doc from jakarta. Defines the provider resolution strategy.
This resolver returns the list of providers evaluated
to build the
If no resolver is defined, the default
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final Validation. | |
| private final WeakHashMap |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private synchronized void | |
| public static synchronized void | |
| private synchronized List | |
| public static synchronized List | |
| private List | |
| public List |
| INSTANCE | back to summary |
|---|---|
| private static final Validation. | |
| providersPerClassloader | back to summary |
|---|---|
| private final WeakHashMap<ClassLoader, SoftReference<List<ValidationProvider<?>>>> providersPerClassloader | |
| GetValidationProviderListAction | back to summary |
|---|---|
| private GetValidationProviderListAction() | |
| cacheValidationProviders | back to summary |
|---|---|
| private synchronized void cacheValidationProviders(ClassLoader classLoader, List<ValidationProvider<?>> providers) | |
| clearCache | back to summary |
|---|---|
| public static synchronized void clearCache() | |
| getCachedValidationProviders | back to summary |
|---|---|
| private synchronized List | |
| getValidationProviderList | back to summary |
|---|---|
| public static synchronized List | |
| loadProviders | back to summary |
|---|---|
| private List | |
| run | back to summary |
|---|---|
| public List Implements java. Doc from java. Performs the computation. This method will be called by
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static <T extends ValidationProvider | |
| public T |
| clazz | back to summary |
|---|---|
| private final Class<T> clazz | |
| NewProviderInstance | back to summary |
|---|---|
| private NewProviderInstance(Class<T> clazz) | |
| action | back to summary |
|---|---|
| public static <T extends ValidationProvider | |
| run | back to summary |
|---|---|
| public T run() Implements java. Doc from java. Performs the computation. This method will be called by
| |
| Modifier and Type | Field and Description |
|---|---|
| private ValidationProviderResolver | |
| private final Class |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public T | Returns: aConfiguration sub interface implementationImplements jakarta. byProvider(Class)
and delegates the creation of this specific Configuration subclass to the
provider.
|
| public ProviderSpecificBootstrap | Returns: selfValidationProviderResolver implementation usedImplements jakarta. |
| private <P> P |
| resolver | back to summary |
|---|---|
| private ValidationProviderResolver resolver | |
| validationProviderClass | back to summary |
|---|---|
| private final Class<U> validationProviderClass | |
| ProviderSpecificBootstrapImpl | back to summary |
|---|---|
| public ProviderSpecificBootstrapImpl(Class<U> validationProviderClass) | |
| configure | back to summary |
|---|---|
| public T configure() Implements jakarta. Determines the provider implementation suitable for
| |
| providerResolver | back to summary |
|---|---|
| public ProviderSpecificBootstrap Implements jakarta. Optionally defines the provider resolver implementation used. If not defined, use the default ValidationProviderResolver.
| |
| run | back to summary |
|---|---|
| private <P> P run(PrivilegedAction<P> action) | |