Spring Boot can’t autowire @ConfigurationProperties

This is expected as @ConfigurationProperties does not make a class a Spring Component. Mark the class with @Component and it should work. Note that a class can only be injected if it is a Component.

Edit: From Spring 2.2+ (Reference)
@ConfigurationProperties scanning
Classes annotated with @ConfigurationProperties can now be found via classpath scanning as an alternative to using @EnableConfigurationProperties or @Component.

Add @ConfigurationPropertiesScan to your application to enable scanning.

Leave a Comment