From f2e09842ede67906f5758ad2177e20ec63b5b298 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) 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> --- .../hibernate/validator/DefaultConstraintValidatorFactory.java | 2 ++ 1 file changed, 2 insertions(+) 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 {