Spring Boot can't autowire ConfigurationProperties
Object-Oriented Design practice on Codemia
Turn requirements into classes, and defend the design, on the problems that come up in OOD rounds.
Introduction
When Spring Boot fails to autowire a @ConfigurationProperties bean, it is almost always because the bean was never registered in the application context. @ConfigurationProperties alone does not create a bean. You must either add @EnableConfigurationProperties, use @ConfigurationPropertiesScan, or annotate the class with @Component. Without one of these, Spring has no bean to inject and throws NoSuchBeanDefinitionException.
The Error
The Problem
@ConfigurationProperties tells Spring how to bind properties, but it does not register the class as a Spring bean.
Fix 1: @EnableConfigurationProperties (Recommended)
Add @EnableConfigurationProperties to your main class or a @Configuration class:
This explicitly registers AppConfig as a bean and binds properties to it.
Fix 2: @ConfigurationPropertiesScan (Spring Boot 2.2+)
Automatically scans for @ConfigurationProperties classes:
This registers every @ConfigurationProperties class in the specified package without listing each one individually.
Fix 3: @Component
Add @Component to the properties class:
This works but is not recommended because it mixes configuration binding with component scanning. The Spring Boot team prefers @EnableConfigurationProperties.
Fix 4: @Bean Method in @Configuration
Define the bean explicitly:
This approach is useful when you need custom initialization logic or when the properties class comes from a third-party library you cannot annotate.
Constructor Binding (Spring Boot 2.2+)
Use @ConstructorBinding for immutable configuration:
Constructor-bound classes cannot use @Component. They must be registered via @EnableConfigurationProperties or @ConfigurationPropertiesScan.
Nested Properties
Spring Boot automatically maps kebab-case (pool-size) to camelCase (poolSize).
Validation
Add spring-boot-starter-validation to your dependencies. The application fails to start if properties violate constraints, giving you immediate feedback.
Injecting the Bean
Common Pitfalls
- Missing
@EnableConfigurationProperties: The most common cause.@ConfigurationPropertiesalone does not create a bean. You must explicitly enable it. - Wrong prefix: If
@ConfigurationProperties(prefix = "app")does not match your YAML/properties keys, binding silently produces null values. Spring does not throw an error for missing properties unless you add@Validatedwith@NotNull. - Missing getters/setters: Property binding requires standard JavaBean setters (or constructor parameters for constructor binding). Without them, values are silently ignored.
@ConstructorBindingwith@Component: Constructor binding is incompatible with@Component. Use@EnableConfigurationPropertiesor@ConfigurationPropertiesScaninstead.- Incorrect package scanning:
@ConfigurationPropertiesScanonly scans the specified packages. If your properties class is in a different package, it will not be found.
Summary
@ConfigurationPropertiesbinds properties but does not create a Spring bean- Use
@EnableConfigurationProperties(YourConfig.class)to register the bean explicitly - Use
@ConfigurationPropertiesScanto auto-detect all@ConfigurationPropertiesclasses - Constructor binding creates immutable config objects but requires
@EnableConfigurationProperties - Add
@Validatedwith JSR-303 annotations for startup-time validation of properties - Prefer constructor injection when using
@ConfigurationPropertiesbeans in services
Related reading
- Spring Boot Inherit application.properties from dependency
- spring boot test unable to inject TestRestTemplate and MockMvc
- Spring @Component versus @Bean
- Spring get all Beans of certain interface AND type
- Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup
- Spring Boot ClassNotFoundException when configuring maxUploadSize of CommonMultipartResolver
- Spring injects dependencies in constructor without Autowired annotation
- Spring Why do we autowire the interface and not the implemented class?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Object-Oriented Design practice on Codemia
Turn requirements into classes, and defend the design, on the problems that come up in OOD rounds.