Skip to content
Ameen Abozaid
Planned lessonJNR-012-L02

Typed configuration with @ConfigurationProperties

  • Lesson 2 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

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 @ConfigurationPropertiesScan or @EnableConfigurationProperties.
  • Kebab-case in YAML (page-size-max) maps to camelCase in Java.
  • Prefer this over @Value scattered around the code.
Draft outline details

Demonstration

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

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.