Skip to content

Commit 6d4f023

Browse files
committed
Polish "Fix ConditionalOnProperty when used in an aliased composed annotation"
See gh-30505
1 parent dc57ad5 commit 6d4f023

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.core.Ordered;
2828
import org.springframework.core.annotation.AnnotationAttributes;
2929
import org.springframework.core.annotation.MergedAnnotation;
30-
import org.springframework.core.annotation.MergedAnnotation.Adapt;
3130
import org.springframework.core.annotation.MergedAnnotationPredicates;
3231
import org.springframework.core.annotation.Order;
3332
import org.springframework.core.env.PropertyResolver;
@@ -49,12 +48,10 @@ class OnPropertyCondition extends SpringBootCondition {
4948

5049
@Override
5150
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
52-
Adapt[] adaptations = Adapt.values(false, true);
5351
List<AnnotationAttributes> allAnnotationAttributes = metadata.getAnnotations()
5452
.stream(ConditionalOnProperty.class.getName())
5553
.filter(MergedAnnotationPredicates.unique(MergedAnnotation::getMetaTypes))
56-
.map((annotation) -> annotation.asAnnotationAttributes(adaptations)).collect(Collectors.toList());
57-
54+
.map(MergedAnnotation::asAnnotationAttributes).collect(Collectors.toList());
5855
List<ConditionMessage> noMatch = new ArrayList<>();
5956
List<ConditionMessage> match = new ArrayList<>();
6057
for (AnnotationAttributes annotationAttributes : allAnnotationAttributes) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ void metaAndDirectAnnotationWithAliasConditionDoesNotMatchWhenOnlyMetaPropertyIs
259259
assertThat(this.context.containsBean("foo")).isFalse();
260260
}
261261

262+
@Test
263+
void metaAndDirectAnnotationWithAliasConditionDoesNotMatchWhenOnlyDirectPropertyIsSet() {
264+
load(MetaAnnotationAndDirectAnnotationWithAlias.class, "my.other.feature.enabled=true");
265+
assertThat(this.context.containsBean("foo")).isFalse();
266+
}
267+
262268
@Test
263269
void metaAndDirectAnnotationWithAliasConditionMatchesWhenBothPropertiesAreSet() {
264270
load(MetaAnnotationAndDirectAnnotationWithAlias.class, "my.feature.enabled=true",

0 commit comments

Comments
 (0)