Skip to content

Commit 6bd438a

Browse files
committed
Document @ConditionalOnProperty limitation with collections
Closes gh-7483
1 parent 57515df commit 6bd438a

File tree

1 file changed

+15
-0
lines changed
  • spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.springframework.boot.autoconfigure.couchbase.OnBootstrapHostsCondition;
2526
import org.springframework.context.annotation.Conditional;
2627
import org.springframework.core.env.Environment;
2728

@@ -72,6 +73,20 @@
7273
* {@link #matchIfMissing()} attribute is consulted. By default missing attributes do not
7374
* match.
7475
*
76+
* <p>
77+
* This condition cannot be reliably used for matching collection properties. For example,
78+
* in the following configuration, the condition matches if {@code spring.example.values}
79+
* is present in the {@link Environment} but does not match if {@code spring.example.values[0]} is present.
80+
*
81+
* <pre class="code">
82+
* &#064;ConditionalOnProperty(prefix = "spring", name = "example.values")
83+
* class ExampleAutoConfiguration {
84+
* }
85+
* </pre>
86+
*
87+
* It is better to use a custom condition for such cases.
88+
* See {@link OnBootstrapHostsCondition} for an example of a custom condition.
89+
*
7590
* @author Maciej Walkowiak
7691
* @author Stephane Nicoll
7792
* @author Phillip Webb

0 commit comments

Comments
 (0)