From 5510c6f61b6ce59877ea0e99595ea379a3b64aa5 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 22 Apr 2024 14:27:54 +0200 Subject: [PATCH] Clarify that all named properties must match for @ConditionalOnProperty to match Closes gh-40110 --- .../boot/autoconfigure/condition/ConditionalOnProperty.java | 5 ++++- .../asciidoc/features/developing-auto-configuration.adoc | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnProperty.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnProperty.java index a4b8f947b58..8bd4647a0cd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnProperty.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnProperty.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,6 +117,9 @@ public @interface ConditionalOnProperty { *

* Use the dashed notation to specify each property, that is all lower case with a "-" * to separate words (e.g. {@code my-long-property}). + *

+ * If multiple names are specified, all of the properties have to pass the test for + * the condition to match. * @return the names */ String[] name() default {}; diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc index ce6c3dbf8bb..4a4a1eff945 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc @@ -114,6 +114,8 @@ Use the `prefix` and `name` attributes to specify the property that should be ch By default, any property that exists and is not equal to `false` is matched. You can also create more advanced checks by using the `havingValue` and `matchIfMissing` attributes. +If multiple names are given in the `name` attribute, all of the properties have to pass the test for the condition to match. + [[features.developing-auto-configuration.condition-annotations.resource-conditions]]