@EnableConfigurationProperties registers one or more @ConfigurationProperties classes as Spring beans and turns on binding of external properties (from application.properties, application.yml, environment variables and command-line arguments) onto them. In Spring Boot the infrastructure for binding is already enabled by auto-configuration, so the annotation is mostly used as a precise, explicit way to register properties classes that are not found by component scanning.
It is not a way to make a plain class "Spring-managed by magic". It does one thing: for each class you list, it creates a bean definition and lets the binder fill it from the Environment.
@EnableConfigurationProperties does@EnableConfigurationProperties does@ConfigurationProperties on its own only marks a class as a binding target and sets a prefix. Something still has to create the bean. There are four common ways to do that:
| Approach | Where it is used | Notes |
|---|---|---|
@Component on the properties class | Class is inside a scanned package | Simple, but the class now depends on component scanning |
@EnableConfigurationProperties(MyProps.class) | On any @Configuration class | Explicit; works for classes outside the scan path and in libraries |
@ConfigurationPropertiesScan | On the application class | Scans a package for @ConfigurationProperties classes |
@Bean method annotated with @ConfigurationProperties | Third-party classes you cannot edit | Binds onto the object the method returns |
When you list a class in @EnableConfigurationProperties, Spring registers a bean for it (named from the prefix and the class name) and the ConfigurationPropertiesBindingPostProcessor binds values to it.
Define the properties as an immutable record. Since Spring Boot 3, a class or record with a single parameterized constructor is bound through that constructor automatically, so @ConstructorBinding is only needed when a class has several constructors.
Register it from a configuration class:
Provide the values in application.yml:
Now MailProperties can be injected like any bean:
You can list several classes at once: @EnableConfigurationProperties({DatabaseProps.class, ServerProps.class}). Binding is relaxed, so app.mail.host, APP_MAIL_HOST and app.mail.Host all map to the host component.
Spring Boot ships ConfigurationPropertiesAutoConfiguration, which already applies @EnableConfigurationProperties for you. That means you never have to add the annotation just to switch binding on in a Boot application. You only use it to name the classes to register.
If you would rather not list classes one by one, scan for them:
Do not combine approaches for the same class. Annotating a class with @Component and also listing it in @EnableConfigurationProperties can produce two bean definitions and a NoUniqueBeanDefinitionException at injection time.
In a plain Spring Framework application there is no auto-configuration, so the @EnableConfigurationProperties annotation (which imports the binding infrastructure) is what activates property binding at all. You also need the spring-boot module on the classpath, because the annotation and the binder live in org.springframework.boot, not in Spring Framework core.
Add @Validated and Jakarta Bean Validation constraints to fail fast on bad configuration. This requires a validator implementation such as spring-boot-starter-validation.
If app.mail.host is missing, the application fails to start with a binding error that names the property. For a class you do not own, put @ConfigurationProperties on a @Bean method instead:
@ConfigurationProperties on a class and expecting it to be a bean without @Component, @EnableConfigurationProperties or @ConfigurationPropertiesScan. Nothing is created, so injection fails with NoSuchBeanDefinitionException.spring-boot-configuration-processor annotation processor, which generates metadata so IDEs can auto-complete your custom properties.ignoreUnknownFields = false if you want them to fail.@EnableConfigurationProperties required in Spring Boot?No. Boot already enables the binding infrastructure. You need the annotation, a @Component, or @ConfigurationPropertiesScan only to register each properties class as a bean.
@ConfigurationProperties and @Value?@ConfigurationProperties binds a whole group of related, typed properties with relaxed naming and validation. @Value injects a single value using SpEL or a placeholder and does not support relaxed binding in the same way.
Yes. Records bind through their canonical constructor. Use @DefaultValue to supply defaults for missing properties.
On any @Configuration class that Spring processes, often one per module. It does not have to be on the main application class.
@EnableConfigurationProperties registers the listed @ConfigurationProperties classes as beans and binds external configuration to them. In Spring Boot, binding is already switched on by auto-configuration, so the annotation is an explicit alternative to @Component and @ConfigurationPropertiesScan. Prefer immutable records, add validation, and keep one registration route per class.