Spring Boot: Configuration properties bind to a typed record

@ConfigurationProperties gives you validated, IDE-completable config instead of scattered @Value strings.

Code
@ConfigurationProperties(prefix = "app.mail")
@Validated
record MailProperties(@NotBlank String host, int port, boolean enabled) { }

@EnableConfigurationProperties(MailProperties.class)
@SpringBootApplication
class App { }

// application.yml
// app.mail.host: smtp.example.com
// app.mail.port: 587
Output
MailProperties[host=smtp.example.com, port=587, enabled=false]
A blank host fails at STARTUP with a clear message, not at the first send.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11