Browse Source

Correct docs for use of static with @ConfigurationPropertiesBinding

Closes gh-45621
pull/45654/head
Andy Wilkinson 7 months ago
parent
commit
bdf0ef19a4
  1. 3
      spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc
  2. 4
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java
  3. 7
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinding.java

3
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. 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. 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]. 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.

4
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationProperties.java

@ -37,10 +37,6 @@ import org.springframework.stereotype.Indexed;
* <p> * <p>
* Note that contrary to {@code @Value}, SpEL expressions are not evaluated since property * Note that contrary to {@code @Value}, SpEL expressions are not evaluated since property
* values are externalized. * values are externalized.
* <p>
* 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 * @author Dave Syer
* @since 1.0.0 * @since 1.0.0

7
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
/** /**
* Qualifier for beans that are needed to configure the binding of * Qualifier for beans that are needed to configure the binding of
* {@link ConfigurationProperties @ConfigurationProperties} (e.g. Converters). * {@link ConfigurationProperties @ConfigurationProperties} (e.g. Converters).
* <p>
* {@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 * @author Dave Syer
* @since 1.3.0 * @since 1.3.0

Loading…
Cancel
Save