Difference between @ConfigurationProperties and @Value
@Value is a core container feature and it does not provide the same features as type-safe Configuration
Properties. The table below summarizes the features that are supported by @ConfigurationProperties and @Value:
Feature |
@ConfigurationProperties |
@Value |
Relaxed binding |
Yes |
No |
Meta-data support |
Yes |
No |
SpEL evaluation |
No |
Yes |
If you define a set of configuration keys for your own components, spring boot recommends you to group them
in a POJO annotated with @ConfigurationProperties. Please also be aware that since @Value does not support relaxed binding,
it isn’t a great candidate if you need to provide the value using environment variables.
Finally, while you can write a SpEL expression in @Value, such expressions are not processed from Application property files.
|