From fa0107c431c76c5590d1c1255bf692600bd1271b Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 20 May 2025 12:53:03 -0700 Subject: [PATCH] Document @ConfigurationPropertiesBinding should use static bean methods Closes gh-45621 --- .../reference/pages/features/external-config.adoc | 10 ++++++++-- .../context/properties/ConfigurationProperties.java | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc index d4138c6ba78..c82bee2ec10 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc @@ -1137,9 +1137,15 @@ NOTE: The preceding merging rules apply to properties from all property sources, Spring Boot attempts to coerce the external application properties to the right type when it binds to the javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans. If you need custom type conversion, you can provide a javadoc:org.springframework.core.convert.ConversionService[] bean (with a bean named `conversionService`) or custom property editors (through a javadoc:org.springframework.beans.factory.config.CustomEditorConfigurer[] bean) or custom converters (with bean definitions annotated as javadoc:org.springframework.boot.context.properties.ConfigurationPropertiesBinding[format=annotation]). -NOTE: As this bean is requested very early during the application lifecycle, make sure to limit the dependencies that your javadoc:org.springframework.core.convert.ConversionService[] is using. +[NOTE] +==== +Beans used for property conversion are requested very early during the application lifecycle so make sure to limit the dependencies that your javadoc:org.springframework.core.convert.ConversionService[] is using. Typically, any dependency that you require may not be fully initialized at creation time. -You may want to rename your custom javadoc:org.springframework.core.convert.ConversionService[] if it is not required for configuration keys coercion and only rely on custom converters qualified with javadoc:org.springframework.boot.context.properties.ConfigurationPropertiesBinding[format=annotation]. + +You should also declare any javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans using `static` methods to avoid "`bean is not eligible for getting processed by all BeanPostProcessors`" warnings. +==== + +TIP: You may want to rename your custom javadoc:org.springframework.core.convert.ConversionService[] if it is not required for configuration keys coercion and only rely on custom converters qualified with javadoc:org.springframework.boot.context.properties.ConfigurationPropertiesBinding[format=annotation]. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java index 7c8c41e05ad..547d09860c8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java @@ -37,6 +37,10 @@ import org.springframework.stereotype.Indexed; *

* Note that contrary to {@code @Value}, SpEL expressions are not evaluated since property * values are externalized. + *

+ * Static methods should be used when declaring {@code @ConfigurationProperties} beans to + * ensure that "bean is not eligible for getting processed by all BeanPostProcessors" + * warnings are not produced. * * @author Dave Syer * @since 1.0.0