Commit 277da462 authored by Stephane Nicoll's avatar Stephane Nicoll

Document differences between @Value and @ConfigurationProperties

Closes gh-4892
parent a72e4948
...@@ -734,8 +734,8 @@ Nested POJO properties can also be created (so a setter is not mandatory) if the ...@@ -734,8 +734,8 @@ Nested POJO properties can also be created (so a setter is not mandatory) if the
default constructor, or a constructor accepting a single value that can be coerced from default constructor, or a constructor accepting a single value that can be coerced from
String. Some people use Project Lombok to add getters and setters automatically. String. Some people use Project Lombok to add getters and setters automatically.
NOTE: Contrary to `@Value`, SpEL expressions are not evaluated prior to injecting a value TIP: See also the <<boot-features-external-config-vs-value,differences between `@Value`
in the relevant `@ConfigurationProperties` bean. and `@ConfigurationProperties`>>.
The `@EnableConfigurationProperties` annotation is automatically applied to your project The `@EnableConfigurationProperties` annotation is automatically applied to your project
so that any beans annotated with `@ConfigurationProperties` will be configured from the so that any beans annotated with `@ConfigurationProperties` will be configured from the
...@@ -954,6 +954,43 @@ _<<production-ready-features.adoc#production-ready-endpoints, Production ready f ...@@ -954,6 +954,43 @@ _<<production-ready-features.adoc#production-ready-endpoints, Production ready f
section for details. section for details.
[[boot-features-external-config-vs-value]]
==== @ConfigurationProperties vs. @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`:
[cols="4,2,2"]
|===
|Feature |`@ConfigurationProperties` |`@Value`
| <<boot-features-external-config-relaxed-binding,Relaxed binding>>
| Yes
| No
| <<appendix-configuration-metadata.adoc#configuration-metadata,Meta-data support>>
| Yes
| No
| `SpEL` evaluation
| No
| Yes
|===
If you define a set of configuration keys for your own components, we recommend 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 <<boot-features-external-config-application-property-files,Application
property files>>.
[[boot-features-profiles]] [[boot-features-profiles]]
== Profiles == Profiles
Spring Profiles provide a way to segregate parts of your application configuration and Spring Profiles provide a way to segregate parts of your application configuration and
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment