@ConfigurationProperties binds a group of external properties, such as those under app.mail in application.yml, to a typed Java object. It gives you structured, validated and IDE-friendly configuration in place of scattered @Value lookups.
Spring Boot performs relaxed binding, type conversion and optional bean validation, so app.mail.max-retries, APP_MAIL_MAXRETRIES and app.mail.maxRetries all map to the same field.
Annotate a class with a prefix and expose its values. Since Spring Boot 3, the cleanest option is an immutable record with constructor binding.
Duration is converted from 5s automatically, and the YAML list becomes a List<String>.
The class has to be registered as a bean. Pick one of these.
A class that is also a @Component can be bound too, but records and constructor binding need @EnableConfigurationProperties or @ConfigurationPropertiesScan.
Inject the properties object like any bean.
Add spring-boot-starter-validation and Jakarta Bean Validation annotations, then mark the class with @Validated. Startup fails with a clear message when a value is wrong.
Nested records map to nested keys, and @DefaultValue supplies a fallback when a key is absent. This keeps related settings together and removes null checks.
With this file, enabled is true, ttl is ten minutes and redis.port is 6379. Only redis.host has to be supplied. Property names in code use camelCase, and the YAML keys use kebab-case, which is the recommended style.
| Aspect | @ConfigurationProperties | @Value |
|---|---|---|
| Relaxed binding | Yes | Limited |
| Grouped, nested objects | Yes | No |
| Validation | Yes | Manual |
| Metadata for IDE completion | Yes, with the annotation processor | No |
| SpEL expressions | No | Yes |
Use @Value for a single isolated value or when you need SpEL. Use @ConfigurationProperties for anything structured.
Add spring-boot-configuration-processor as an annotation processor. It generates META-INF/spring-configuration-metadata.json, which gives autocomplete and documentation for your own keys in application.yml.
Not with constructor binding. A record or a class with a single parameterized constructor binds through it. JavaBean-style binding needs getters and setters.
Declare a List or Map field. YAML lists work directly, and in .properties files you use indexes such as app.mail.allowed-domains[0].
Not by default. Bound objects are built at startup. Use Spring Cloud refresh scope or restart the application to apply new values.
The field is null or a zero value unless you add validation or a default. Fail fast with @NotNull or @NotBlank.
@ConfigurationProperties turns external configuration into typed, validated, relaxed-bound objects. Prefer records with a prefix, register them with @ConfigurationPropertiesScan, and add validation and the configuration processor for safer, easier-to-maintain configuration.