From fce3cd1684cc0c581f904ec4e3cd6aaacb8126a2 Mon Sep 17 00:00:00 2001 From: Mihail Cornescu Date: Wed, 5 Jan 2022 18:03:29 +0000 Subject: [PATCH] Add a note on early init with @ConditionalOnExpression See gh-29276 --- .../boot/autoconfigure/condition/ConditionalOnExpression.java | 4 ++++ .../docs/asciidoc/features/developing-auto-configuration.adoc | 1 + 2 files changed, 5 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnExpression.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnExpression.java index bdef69f3b7..88547a7e16 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnExpression.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnExpression.java @@ -40,6 +40,10 @@ public @interface ConditionalOnExpression { /** * The SpEL expression to evaluate. Expression should return {@code true} if the * condition passes or {@code false} if it fails. + *

+ * NOTE: Referencing a bean in the expression will cause that bean to be initialized + * very early in context refresh processing. As a result, the bean will load with + * default property values. * @return the SpEL expression */ String value() default "true"; 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 df245f4ee0..2fdbc2c0e2 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 @@ -143,6 +143,7 @@ This condition will not match for applications that are run with an embedded ser ==== SpEL Expression Conditions The `@ConditionalOnExpression` annotation lets configuration be included based on the result of a {spring-framework-docs}/core.html#expressions[SpEL expression]. +NOTE: Referencing a bean in the expression will cause that bean to be initialized very early in context refresh processing. As a result, the bean will load with default property values. [[features.developing-auto-configuration.testing]]