javax.validation

Class 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 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();
       
    • 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();
       

    Note:

    • The ValidatorFactory object built by the bootstrap process should be cached and shared amongst Validator consumers.
    • This class is thread-safe.
    Author:
    Emmanuel Bernard, Hardy Ferentschik
    • Constructor Detail

      • Validation

        public Validation()
    • Method Detail

      • buildDefaultValidatorFactory

        public static ValidatorFactory buildDefaultValidatorFactory()
        Builds and returns a ValidatorFactory 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 to Validation.byDefaultProvider().configure().buildValidatorFactory().

        Returns:
        ValidatorFactory instance
        Throws:
        ValidationException - if the ValidatorFactory cannot be built
      • byDefaultProvider

        public static GenericBootstrap byDefaultProvider()
        Builds a Configuration. 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 a Configuration 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();
         
        , where ACMEConfiguration is the Configuration sub interface uniquely identifying the ACME Bean Validation provider. and ACMEProvider is the ValidationProvider implementation of the ACME provider.
        Parameters:
        providerType - the ValidationProvider implementation type
        Returns:
        instance building a provider specific Configuration sub interface implementation

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

21/08/2025 16:50:53 Cette version de la page est en cache (à la date du 21/08/2025 16:50:53) afin d'accélérer le traitement.
Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.

Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/validation/validation.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.