The code below fails at startup with spring boot 3.1.1 (and works prefectly well in 3.1.0 or 2.7.12):
Caused by: java.lang.IllegalStateException: Cannot bind @ConfigurationProperties for bean 'application.ApplicationConfiguration'. Ensure that @ConstructorBinding has not been applied to regular bean
@SpringBootApplication
public class Application {
@RequiredArgsConstructor
@Configuration
@ConfigurationProperties("application")
public static class ApplicationConfiguration {
private final ApplicationContext ctx;
@Getter
@Setter
private String setting;
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Comment From: wilkinsona
Thanks for the report. 3.0.8 is also affected. The problem does not occur with 3.0.7.
I am surprised this works in any 3.x release due to the changes made to constructor binding detection. You're injecting a "bean" into your @ConfigurationProperties class so you need to use @Autowired to indicate that dependency injection should be used rather than property binding. With Lombok, I think that would be something like @RequiredArgsConstructor(onConstructor=@__(@Autowired))
As a slight aside, we don't recommend mixing @ConfigurationProperties and @Configuration. The former is for accessing your application's configuration properties while the latter is for defining @Bean methods. We recommend keeping the two classes separate and injecting @ConfigurationProperties classes into @Configuration classes as needed.