@ConstructorBinding with @ConfigurationProperties only worked after I added @ConfigurationPropertiesScan to the application boot class.

I found this out in this article: https://www.baeldung.com/configuration-properties-in-spring-boot

Furthermore, it's important to emphasize that to use the constructor binding, we need to explicitly enable our configuration class either with @EnableConfigurationProperties or with @ConfigurationPropertiesScan.

Suggestion: inform the @ConstructorBinding annotation in the JavaDoc that for it to work it is necessary to define @ConfigurationPropertiesScan or @EnableConfigurationProperties.

My property class:

@ConfigurationProperties("app.connection")
@ConstructorBinding
public class ConnectionProperties {
    @NotBlank
    private final String user;
}

More details:

Before I had an error like this

Parameter 2 of constructor in com.xxx.config.Context required a bean of type 'com.xxx.props.ConnectionProperties' that could not be found.

And after annotating my ConnectionProperties class with @Component, I got the error

Parameter 0 of constructor in com.xxx.props.ConnectionProperties required a bean of type 'java.lang.String' that could not be found.

Comment From: mbhave

We mention that in a note in the reference documentation. We could add it in the javadoc too.

Comment From: kandulsh

Would like to work on this issue.

Comment From: mbhave

Closing in favor of PR #28168