- java.lang.Object
-
- javax.validation.Validation
-
public class Validation extends Object
This class is the entry point for Bean Validation. There are three ways to bootstrap it:- The easiest approach is to build the default
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:- if the XML configuration defines a provider, this provider is used
- if the XML configuration does not define a provider or if no XML
configuration is present the first provider returned by the
ValidationProviderResolver
instance is used.
-
The second bootstrap approach allows to choose a custom
ValidationProviderResolver
. The chosenValidationProvider
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();
-
The third approach allows you to specify explicitly and in
a type safe fashion the expected provider.
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();
-
The
ValidatorFactory
object built by the bootstrap process should be cached and shared amongstValidator
consumers. - This class is thread-safe.
- Author:
- Emmanuel Bernard, Hardy Ferentschik
- The easiest approach is to build the default
-
-
Constructor Summary
Constructors Constructor and Description Validation()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static ValidatorFactory
buildDefaultValidatorFactory()
Builds and returns aValidatorFactory
instance based on the default Bean Validation provider and following the XML configuration.static GenericBootstrap
byDefaultProvider()
Builds aConfiguration
.static <T extends Configuration<T>,U extends ValidationProvider<T>>
ProviderSpecificBootstrap<T>byProvider(Class<U> providerType)
Builds aConfiguration
for a particular provider implementation.
-
-
-
Method Detail
-
buildDefaultValidatorFactory
public static ValidatorFactory buildDefaultValidatorFactory()
Builds and returns aValidatorFactory
instance based on the default Bean Validation provider and following the XML configuration. The provider list is resolved using the default validation provider resolver logic. The code is semantically equivalent toValidation.byDefaultProvider().configure().buildValidatorFactory()
.- Returns:
ValidatorFactory
instance- Throws:
ValidationException
- if theValidatorFactory
cannot be built
-
byDefaultProvider
public static GenericBootstrap byDefaultProvider()
Builds aConfiguration
. The provider list is resolved using the strategy provided to the bootstrap state.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.- Returns:
- instance building a generic
Configuration
compliant with the bootstrap state provided
-
byProvider
public static <T extends Configuration<T>,U extends ValidationProvider<T>> ProviderSpecificBootstrap<T> byProvider(Class<U> providerType)
Builds aConfiguration
for a particular provider implementation. 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();
, whereACMEConfiguration
is theConfiguration
sub interface uniquely identifying the ACME Bean Validation provider. andACMEProvider
is theValidationProvider
implementation of the ACME provider.- Parameters:
providerType
- theValidationProvider
implementation type- Returns:
- instance building a provider specific
Configuration
sub interface implementation
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 18/08/2025
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-javaee-rf-javax/validation/validation.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.