You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue seems to have surfaced in 3.0.0 and seems to have been fixed in 3.0.2, and remains fixed through to 3.0.5 inclusive.
In 3.1.1 this behaviour seems to have regressed.
Can be reproduced with the following kotlin example:
@SpringBootApplication
class ConstructorbindingApplication
fun main(args: Array<String>) {
runApplication<ConstructorbindingApplication>(*args)
}
@Component
@ConfigurationProperties("top-level-property")
class ApplicationProperties(
var someProperty: String = ""
) {}
Application runs successfully in 3.0.5, however in 3.1.1 throws the following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationProperties' defined in file [C:\Users\grant\Desktop\constructorbinding\constructorbinding\target\classes\com\example\constructorbinding\ApplicationProperties.class]: Cannot bind @ConfigurationProperties for bean 'applicationProperties'. Ensure that @ConstructorBinding has not been applied to regular bean
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:605) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:941) ~[spring-context-6.0.10.jar:6.0.10]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[spring-context-6.0.10.jar:6.0.10]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.1.jar:3.1.1]
at com.example.constructorbinding.ConstructorbindingApplicationKt.main(ConstructorbindingApplication.kt:23) ~[classes/:na]
Caused by: java.lang.IllegalStateException: Cannot bind @ConfigurationProperties for bean 'applicationProperties'. Ensure that @ConstructorBinding has not been applied to regular bean
at org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-6.0.10.jar:6.0.10]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:92) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:79) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:419) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-6.0.10.jar:6.0.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[spring-beans-6.0.10.jar:6.0.10]
... 14 common frames omitted
Thanks for the report. The problem does not occur with 3.0.9-SNAPSHOT or 3.1.2-SNAPSHOT (available from https://repo.spring.io/snapshot). It has already been fixed by the changes made for #36175.
There were issues previously where spring would attempt constructor binding of @ConfigurationProperties under some circumstances where it should not.
Related to issues #33710 #33509
Issue seems to have surfaced in 3.0.0 and seems to have been fixed in 3.0.2, and remains fixed through to 3.0.5 inclusive.
In 3.1.1 this behaviour seems to have regressed.
Can be reproduced with the following kotlin example:
Application runs successfully in 3.0.5, however in 3.1.1 throws the following exception:
The author of one of the original issues has also noted the regression on the now-closed issue.
Workarounds
The text was updated successfully, but these errors were encountered: