@ConfigurationProperties gives you validated, IDE-completable config instead of scattered @Value strings.
@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
MailProperties[host=smtp.example.com, port=587, enabled=false]
A blank host fails at STARTUP with a clear message, not at the first send.
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