Validating configuration
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
fail fast on bad settings.
Planned topics
- Add
@Validatedto the properties type and bean validation constraints to its components. - If a value is missing or invalid, startup fails with a message naming the property.
- Failing at startup beats a failure at 3 a.m. on the first request.
- Use sensible constraints:
@NotBlank,@Min,@DecimalMin.
Draft outline details
Demonstration
@Validated @ConfigurationProperties("shop")
public record ShopProperties(
@NotBlank String currency,
@DecimalMin("0.00") @DecimalMax("1.00") BigDecimal taxRate,
@Min(1) @Max(100) int pageSizeMax) {}Check your understanding
When is a bad value detected?
Show answer
At startup, before the app serves traffic.
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.