From cc20d9120c2d7c0a7dd2229187b306040e31f3da Mon Sep 17 00:00:00 2001 From: Sergio del Amo Date: Mon, 19 Feb 2024 13:14:32 +0100 Subject: [PATCH] fix: add @Primary annotation for DefaultConstraintValidatorFactory (#370) * fix(deps): update dependency io.micronaut.validation:micronaut-validation-bom to v4.4.0 * fix: add @Primary annotation for DefaultConstraintValidatorFactory A `ConstraintValidationFactory` aws added to Micronaut Validation in [PR 288](https://github.com/micronaut-projects/micronaut-validation/pull/288). This PR sets the Hibernate Validator as the primary `ConstraintValidatorFactory` in case there are many in the classpath and avoids: ``` Caused by: io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [DefaultInternalConstraintValidatorFactory, DefaultConstraintValidatorFactory] ``` see: https://github.com/micronaut-projects/micronaut-sql/issues/1266 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- gradle/libs.versions.toml | 2 +- .../hibernate/validator/DefaultConstraintValidatorFactory.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5fe8fc48..62cf724e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ managed-hibernate-validator = '8.0.1.Final' micronaut-serde = "2.8.1" micronaut-test = "4.0.0" -micronaut-validation = "4.2.0" +micronaut-validation = "4.4.0" groovy = "4.0.13" diff --git a/hibernate-validator/src/main/java/io/micronaut/configuration/hibernate/validator/DefaultConstraintValidatorFactory.java b/hibernate-validator/src/main/java/io/micronaut/configuration/hibernate/validator/DefaultConstraintValidatorFactory.java index 2ae265c9..25d0c25b 100644 --- a/hibernate-validator/src/main/java/io/micronaut/configuration/hibernate/validator/DefaultConstraintValidatorFactory.java +++ b/hibernate-validator/src/main/java/io/micronaut/configuration/hibernate/validator/DefaultConstraintValidatorFactory.java @@ -16,6 +16,7 @@ package io.micronaut.configuration.hibernate.validator; import io.micronaut.context.BeanContext; +import io.micronaut.context.annotation.Primary; import io.micronaut.context.exceptions.NoSuchBeanException; import io.micronaut.core.reflect.InstantiationUtils; import io.micronaut.inject.DisposableBeanDefinition; @@ -31,6 +32,7 @@ * @author James Kleeh * @since 1.1.0 */ +@Primary @Singleton public class DefaultConstraintValidatorFactory implements ConstraintValidatorFactory {