Reopening to check why Spring Cloud need to make this change. The exception they have is:
08:34:17 Caused by: java.lang.IllegalStateException: Cannot bind @ConfigurationProperties for bean 'configServerHealthIndicator'. Ensure that @ConstructorBinding has not been applied to regular bean
08:34:17 at org.springframework.util.Assert.state(Assert.java:76)
08:34:17 at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:86)
08:34:17 at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:78)
08:34:17 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:425)
08:34:17 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1733)
08:34:17 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:416)
08:34:17 at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.rebind(ConfigurationPropertiesRebinder.java:105)
08:34:17 at org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration.afterSingletonsInstantiated(ConfigurationPropertiesRebinderAutoConfiguration.java:73)
08:34:17 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:945)
08:34:17 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:917)
08:34:17 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
08:34:17 at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
08:34:17 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:720)
08:34:17 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:401)
08:34:17 at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
08:34:17 at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:124)
08:34:17 at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
08:34:17 at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:123)
08:34:17 ... 39 common frames omitted
It seems like we should have detected that it was from a @Bean method.
Comment From: philwebb
See #23216
Comment From: mbhave
Spring Cloud's ConfigurationPropertiesRebinder calls initializeBean on beans that it does not own, ie those bean definitions are in the parent context. When the ConfigurationPropertiesBindingPostProcessor is called, it does not find the bean definition (because it’s not in the current context). Spring Cloud could fix this by calling destroy and initializeBean on the application context which contains the bean definition, using the containsLocalBean check to go up the hierarchy. Applying post processors on a bean that the context does not own is not something that we'd expect to handle in the ConfigurationPropertiesBindingPostProcessor.
Comment From: wind57
@philwebb
We have the same problem in spring-cloud-kubernetes when trying to move something to records. I have a reproducible sample here, take a look at record.binding package.
If I change SampleProperties to :
@ConfigurationProperties("org.sample")
public record SampleProperties() {
}
i.e.: drop its arguments, then the test passes. Should I open a new issue? thank you.
Comment From: wilkinsona
@wind57, I can't see the connection between this issue and your sample as it doesn't appear to have any @Bean methods. If you believe you've found a bug, please open a new issue minimising the sample that reproduces the problem.
Comment From: wind57
ok, thank you. the only reason I put it here was because of the error message.
Comment From: philwebb
I've opened https://github.com/spring-cloud/spring-cloud-commons/issues/1158