Typed configuration with @ConfigurationProperties
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
bind settings to a record.
Planned topics
- Group related settings under a prefix and bind them to one class.
- A record gives an immutable, constructor-bound holder.
- Register with
@ConfigurationPropertiesScanor@EnableConfigurationProperties. - Kebab-case in YAML (
page-size-max) maps to camelCase in Java. - Prefer this over
@Valuescattered around the code.
Draft outline details
Demonstration
@ConfigurationProperties(prefix = "shop")
public record ShopProperties(String currency, BigDecimal taxRate, int pageSizeMax) {}Check your understanding
Why a record rather than a class with setters?
Show answer
Immutable: values cannot change after startup.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.