Polish "Fix ConditionalOnProperty when used in an aliased composed annotation"

See gh-30505
This commit is contained in:
Andy Wilkinson 2022-05-05 09:59:43 +01:00
parent dc57ad54d5
commit 6d4f0232ca
2 changed files with 7 additions and 4 deletions

View File

@ -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<AnnotationAttributes> 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<ConditionMessage> noMatch = new ArrayList<>();
List<ConditionMessage> match = new ArrayList<>();
for (AnnotationAttributes annotationAttributes : allAnnotationAttributes) {

View File

@ -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",