diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java index 29bc5c1a51..1508a7ae3b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnPropertyCondition.java @@ -21,6 +21,7 @@ import java.util.List; import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.StringUtils; @@ -42,8 +43,11 @@ class OnPropertyCondition extends SpringBootCondition { List missingProperties = new ArrayList(); + Environment environment = context.getEnvironment(); for (String property : onProperties) { - if (!context.getEnvironment().containsProperty(property)) { + if (!environment.containsProperty(property) + || StringUtils.endsWithIgnoreCase(environment.getProperty(property), + "false")) { missingProperties.add(property); } } @@ -57,5 +61,4 @@ class OnPropertyCondition extends SpringBootCondition { + StringUtils.arrayToCommaDelimitedString(missingProperties .toArray()) + " not found"); } - } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java index 53d77f5aa0..020358846f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnPropertyTests.java @@ -52,6 +52,22 @@ public class ConditionalOnPropertyTests { assertFalse(this.context.containsBean("foo")); } + @Test + public void testBeanIsNotCreatedWhenPropertyValueEqualsFalse() { + EnvironmentTestUtils.addEnvironment(this.context.getEnvironment(), + "property1=false", "property2=value2"); + setupContext(); + assertFalse(this.context.containsBean("foo")); + } + + @Test + public void testBeanIsNotCreatedWhenPropertyValueEqualsFALSE() { + EnvironmentTestUtils.addEnvironment(this.context.getEnvironment(), + "property1=FALSE", "property2=value2"); + setupContext(); + assertFalse(this.context.containsBean("foo")); + } + private void setupContext() { this.context.register(MultiplePropertiesRequiredConfiguration.class); this.context.refresh();