In our code, we have used both strongly-type @ConfigurationProperties based classes as well as @Value labeled attributes. It's important to understand the differences before using them in your application.
@Value is old, preceding Spring Boot by years. It is a powerful annotation, able to inject values as well as accept default values. However, it misses several features many of us have come to rely upon when writing Boot apps, as shown in the following table:
Feature |
@ConfigurationProperties |
@Value |
Relaxed binding |
Yes |
No |
Meta-data support |
Yes |
No |
SpEL evaluation |
No |
Yes |
This matrix documents three critical features:
- Relaxed binding: The ability to match server.port ...