From 6d4f0232ca643dcda2df06bef3a4292e7194a377 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 5 May 2022 09:59:43 +0100 Subject: [PATCH] Polish "Fix ConditionalOnProperty when used in an aliased composed annotation" See gh-30505 --- .../boot/autoconfigure/condition/OnPropertyCondition.java | 5 +---- .../autoconfigure/condition/ConditionalOnPropertyTests.java | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java index 0529db28897..aa708df0dd0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java @@ -27,7 +27,6 @@ import org.springframework.context.annotation.ConditionContext; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.MergedAnnotation; -import org.springframework.core.annotation.MergedAnnotation.Adapt; import org.springframework.core.annotation.MergedAnnotationPredicates; import org.springframework.core.annotation.Order; import org.springframework.core.env.PropertyResolver; @@ -49,12 +48,10 @@ class OnPropertyCondition extends SpringBootCondition { @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - Adapt[] adaptations = Adapt.values(false, true); List allAnnotationAttributes = metadata.getAnnotations() .stream(ConditionalOnProperty.class.getName()) .filter(MergedAnnotationPredicates.unique(MergedAnnotation::getMetaTypes)) - .map((annotation) -> annotation.asAnnotationAttributes(adaptations)).collect(Collectors.toList()); - + .map(MergedAnnotation::asAnnotationAttributes).collect(Collectors.toList()); List noMatch = new ArrayList<>(); List match = new ArrayList<>(); for (AnnotationAttributes annotationAttributes : allAnnotationAttributes) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java index 2000a347290..4bd89c1b5a5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java @@ -259,6 +259,12 @@ class ConditionalOnPropertyTests { assertThat(this.context.containsBean("foo")).isFalse(); } + @Test + void metaAndDirectAnnotationWithAliasConditionDoesNotMatchWhenOnlyDirectPropertyIsSet() { + load(MetaAnnotationAndDirectAnnotationWithAlias.class, "my.other.feature.enabled=true"); + assertThat(this.context.containsBean("foo")).isFalse(); + } + @Test void metaAndDirectAnnotationWithAliasConditionMatchesWhenBothPropertiesAreSet() { load(MetaAnnotationAndDirectAnnotationWithAlias.class, "my.feature.enabled=true",