[Index](../README.md) · [Relaxed binding →](02-relaxed-binding.md) # 1. Two mechanisms, not two styles `@Value` and `@ConfigurationProperties` are often presented as a matter of taste. They are not. They are two different mechanisms that happen to read from the same `Environment`, and almost every difference in behaviour follows from that. ## `@Value` is placeholder resolution `@Value("${demo.mail.host}")` is a string. Spring's `PropertySourcesPlaceholderConfigurer` resolves it against the environment during bean post-processing, converts the result to the field's type, and assigns it. There is no model of what a property *is* — only a name, a lookup and a conversion. Consequences: - The property name lives in a string literal. Renaming a property is a text search. - One field, one lookup. There is no way to express "these six properties belong together". - Defaulting is `:` inside the placeholder, and nothing else. - There is no validation step, because there is no object to validate. - SpEL is available: `#{...}` can compute rather than look up. ## `@ConfigurationProperties` is binding `Binder` walks a target type, works out which properties it needs, asks the `ConfigurationPropertySource`s for each one, converts, and constructs the object. The target type is the model. Consequences: - The property names are derived from the type. Renaming a component renames the property. - Nested types, lists and maps bind, because the binder knows the shape it is filling. - Defaults are `@DefaultValue`, applied per component during construction. - The bound object can be validated as an object, once, at startup. - No SpEL. The binder maps values; it does not compute them. ## The one that surprises people Because both read from the same environment, the *relaxed* rules ought to differ — and in the Spring Framework alone they do. Inside Spring Boot they largely do not, because Boot attaches an extra property source that gives placeholder resolution the binder's name matching. [Chapter 2](02-relaxed-binding.md) has the measured matrix. ## Which to use Use `@ConfigurationProperties` for anything that is a group of settings — which is most things. Reach for `@Value` when you need a single value in a place where a type would be ceremony, or when you need SpEL. [Chapter 6](06-when-value-still-wins.md) is the honest list.