Consider the following example that is target for regular classpath scanning

@Component
@ConstructorBinding
@ConfigurationProperties("brol")
public class BrolProperties {

    private final String endpoint;

    BrolProperties(String endpoint) {
        this.endpoint = endpoint;
    }

This fails with the following exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brolProperties': @EnableConfigurationProperties or @ConfigurationPropertiesScan must be used to add @ConstructorBinding type sample.service.BrolProperties
    at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:60) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at sample.service.ServiceApplication.main(ServiceApplication.java:35) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.0.RELEASE.jar:2.2.0.RELEASE]

Removing @Component fixes the issue but I think the error message could be reworded to make that a bit more explicit.

Comment From: onobc

@snicoll you mind if I grab this one?

Comment From: snicoll

Thanks for the offer but we're reconsidering this mechanism (see #18652) and this may have consequences on this one.

Comment From: onobc

Yeh I saw quite a few other similar issues for the new ConfigurationProperties binding and thought that may be the case. I will keep looking for other candidates.

Comment From: checketts

@snicoll Thanks for the example of the failing application and the explanation of removing @Component.

I ran into the same error message when I had an @Import of my ConfigurationProperties class: @Import({BrolProperties.class})

Removing the @Import also fixed the problem.

Comment From: eduanb

Ran into this issue today. When specifying the class with @ConfigurationProperties in org.springframework.boot.autoconfigure.EnableAutoConfiguration= in spring.factories and having @ConfigurationPropertiesScan you get the same misleading error message.

Comment From: wilkinsona

The changes made for #20798 have changed the error message as failure analysis is now performed. It is now the following:

***************************
APPLICATION FAILED TO START
***************************

Description:

BrolProperties is annotated with @ConstructorBinding but it is defined as a regular bean which caused dependency injection to fail.

Action:

Update your configuration so that BrolProperties is defined via @ConfigurationPropertiesScan or @EnableConfigurationProperties.

It's difficult to be much more specific as, while a class may be annotated with @Component, that isn't enough to be certain that it was registered by component scanning.

WDYT, @snicoll? Can we close this one or should we use it to try to further refine the improvements made in #20798?

Comment From: snicoll

Thanks for the follow-up. Yep, all good, closing this one as being superseded by #20798.