Skip to content

Refine @ConstructorBinding detection logic to support @Bean methods #30395

@philwebb

Description

@philwebb

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.

Metadata

Metadata

Assignees

Labels

for: external-projectFor an external project and not something we can fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions