Type-Safe Configuration with @ConfigurationProperties
Bind properties to typed config classes.
Beyond @Value
Scattering dozens of @Value annotations across a feature is brittle and hard to validate. @ConfigurationProperties binds a whole group of related keys to a single strongly typed object.
You get IDE auto-completion, type safety, validation, and a clear contract for what the feature reads.
Binding a Prefix to a Class
Declare a class with a prefix; Spring maps each key under that prefix to a matching field. Relaxed binding lets max-retries in YAML map to maxRetries in Java.
@ConfigurationProperties(prefix = "app.mail")
public class MailProperties {
private String host;
private int port;
private int maxRetries;
// getters and setters
}All lessons in this course
- application.properties and YAML
- Profiles for Environments
- Type-Safe Configuration with @ConfigurationProperties
- Externalized and Override Configuration