From bdf0ef19a4665567b57a8ac1efe3e32f6c18bcdf Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 21 May 2025 08:39:10 +0100 Subject: [PATCH] Correct docs for use of static with @ConfigurationPropertiesBinding Closes gh-45621 --- .../modules/reference/pages/features/external-config.adoc | 3 +-- .../boot/context/properties/ConfigurationProperties.java | 4 ---- .../context/properties/ConfigurationPropertiesBinding.java | 7 ++++++- 3 files changed, 7 insertions(+), 7 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 c82bee2ec10..115c8d8f5ce 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 @@ -1141,11 +1141,10 @@ If you need custom type conversion, you can provide a javadoc:org.springframewor ==== 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 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]. +When qualifying a `@Bean` method with `@ConfigurationPropertiesBinding`, the method should be `static` to avoid "`bean is not eligible for getting processed by all BeanPostProcessors`" warnings. 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 6caae8ebe75..ca1c7545c5e 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,10 +37,6 @@ 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 diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinding.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinding.java index 5dc39387ffb..4c902941f4b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinding.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2025 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. @@ -23,10 +23,15 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; /** * Qualifier for beans that are needed to configure the binding of * {@link ConfigurationProperties @ConfigurationProperties} (e.g. Converters). + *

+ * {@link Bean @Bean} methods that declare a {@code @ConfigurationPropertiesBinding} bean + * should be {@code static} to ensure that "bean is not eligible for getting processed by + * all BeanPostProcessors" warnings are not produced. * * @author Dave Syer * @since 1.3.0