From 1be06ed2e87633e1e7e0578803c10eeb2304a03d Mon Sep 17 00:00:00 2001 From: Christoph Hermann Date: Thu, 12 Jan 2023 14:15:04 +0100 Subject: [PATCH 1/2] Add native compilation section I'd like to propose an additional section `Native compilation` describing how to use the `Validator` to avoid running into https://github.com/quarkusio/quarkus/issues/7686 --- docs/src/main/asciidoc/validation.adoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/src/main/asciidoc/validation.adoc b/docs/src/main/asciidoc/validation.adoc index 8b05d73542e25..71e086faff1d9 100644 --- a/docs/src/main/asciidoc/validation.adoc +++ b/docs/src/main/asciidoc/validation.adoc @@ -487,6 +487,15 @@ To configure the `ValidatorFactory`, use the exposed configuration properties an Consequently, the only way to define constraints in Quarkus is by annotating your classes. +=== Native compilation + +Building a `Validator` using the `ValidatorFactory` is not possible in native mode. You will end in an +error similar to `javax.validation.NoProviderFoundException: Unable to create a Configuration, because no +Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your +classpath.` + +Always use an injected `Validator`. If you have to configure the `ValidatorFactory` follow the guide at + [[configuration-reference]] == Hibernate Validator Configuration Reference From 934e02611b9600bf8dd998d35947c432c4c7fd5a Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Fri, 27 Jan 2023 17:47:29 +0100 Subject: [PATCH 2/2] Improve new section about Bean Validation and native executables --- docs/src/main/asciidoc/validation.adoc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/src/main/asciidoc/validation.adoc b/docs/src/main/asciidoc/validation.adoc index 71e086faff1d9..8e57b7f8b66e0 100644 --- a/docs/src/main/asciidoc/validation.adoc +++ b/docs/src/main/asciidoc/validation.adoc @@ -487,14 +487,24 @@ To configure the `ValidatorFactory`, use the exposed configuration properties an Consequently, the only way to define constraints in Quarkus is by annotating your classes. -=== Native compilation +=== ValidatorFactory and native executables -Building a `Validator` using the `ValidatorFactory` is not possible in native mode. You will end in an -error similar to `javax.validation.NoProviderFoundException: Unable to create a Configuration, because no +Quarkus provides a default `ValidatorFactory` that you can customize using configuration properties. +This `ValidatorFactory` is carefully initialized to support native executables +using a bootstrap that is Quarkus-specific. + +Creating a `ValidatorFactory` by yourself it not supported in native executables +and if you try to do so, +you will get an error similar to `javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your -classpath.` +classpath.` when running your native executable. + +Thus why you should always use the Quarkus-managed `ValidatorFactory` by injecting an instance of +`ValidatorFactory` or directly an instance of `Validator` using CDI injection. -Always use an injected `Validator`. If you have to configure the `ValidatorFactory` follow the guide at +To support some external libraries that are creating a `ValidatorFactory` using the default bootstrap, +Quarkus returns the `ValidatorFactory` managed by Quarkus when `Validation.buildDefaultValidatorFactory()` +is called. [[configuration-reference]] == Hibernate Validator Configuration Reference