Spring Boot Quiz: @Value/@ConfigurationProperties - Which approach supports type-safe validation and grouping of properties?
Question
A. @Value
B. Environment.getProperty()
C. @ConfigurationProperties
D. All of the above
Answer
C. @ConfigurationProperties
@Value → Injects individual property values, but has no built-in type safety or grouping. You can only bind single values.
Environment.getProperty() → Just a programmatic way to fetch values, again no type safety or validation.
@ConfigurationProperties → Allows us to map groups of related properties into a POJO, supports JSR-303 validation (e.g., @NotNull, @Min), and ensures type-safe binding.
Now Spring validates and binds the config into a strongly-typed bean.
Key Points
app.name→ binds tonameapp.poolSize→ binds topoolSizeValidation kicks in: if
poolSize: 0orname: null, startup will fail with a clear error.Much safer than sprinkling
@Value("${app.name}")all over.


