Skip to content
Veltoryx Technologies
ProLesson 5.2Intermediate2 min readUpdated 31 October 2026

Type-Safe Configuration with @ConfigurationProperties

Replace fragile @Value annotations with type-safe, validated, immutable Java 21 record configuration classes.

01The fragility of @Value

In early Spring tutorials, developers injected configuration values using the @Value annotation:

java
// The fragile legacy approach
@Service
public class EmailService {

    @Value("${app.mail.host}")
    private String host;

    @Value("${app.mail.port:25}")
    private int port;

    @Value("${app.mail.api-key}")
    private String apiKey;
}

Why @Value becomes a nightmare in enterprise systems:

  1. String-typed property paths: If you have a typo in "${app.mail.api-key}", your IDE won't catch it. The error only surfaces when the bean is instantiated at runtime.
  2. No validation: What if port is configured as -5 or host is left blank? @Value will happily inject invalid data without complaint.
  3. Scattershot configuration: If 8 different services need email settings, you repeat those @Value annotations in 8 different classes.
  4. Poor IDE autocompletion: Your IDE cannot autocomplete properties in application.yml.

Loading the rest of the lesson…