Skip to content
Ameen Abozaid
Planned lessonJNR-012-L03

Validating configuration

  • Lesson 3 of 5
  • Junior
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 @Validated to 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

java
@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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.