Skip to content

Commit 88f8248

Browse files
committed
Clarify documentation of relaxed binding
Update the "Relaxed binding" with a small table of common relaxed property names and when they might be used. Fixes gh-2234
1 parent 6fbccbe commit 88f8248

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

+30-5
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,38 @@ in a similar manner as the `ConnectionSettings` example above.
600600
Spring Boot uses some relaxed rules for binding `Environment` properties to
601601
`@ConfigurationProperties` beans, so there doesn't need to be an exact match between
602602
the `Environment` property name and the bean property name. Common examples where this
603-
is useful include underscore separated (e.g. `context_path` binds to `contextPath`), and
603+
is useful include dashed separated (e.g. `context-path` binds to `contextPath`), and
604604
capitalized (e.g. `PORT` binds to `port`) environment properties.
605605

606-
NOTE: Environment variables are usually underscore-separated and upper case. You can
607-
use that format and Spring Boot will bind them to your bean property names accordingly.
608-
For instance `MY_PROPERTY` will match just the same as `myProperty`, `my_property` or
609-
`my-property`.
606+
For example, given the following `@ConfigurationProperties` class:
607+
608+
[source,java,indent=0]
609+
----
610+
@Component
611+
@ConfigurationProperties(prefix="person")
612+
public class ConnectionSettings {
613+
614+
private String firstName;
615+
616+
}
617+
----
618+
619+
The following properties names can all be used:
620+
621+
.relaxed binding
622+
[cols="1,4"]
623+
|===
624+
| Property | Note
625+
626+
|`person.firstName`
627+
|Standard camel case syntax.
628+
629+
|`person.first-name`
630+
|Dashed notation, recommended for use in `.properties` and `.yml` files.
631+
632+
|`PERSON_FIRST_NAME`
633+
|Upper case format. Recommended when using a system environment variables.
634+
|===
610635

611636
Spring will attempt to coerce the external application properties to the right type when
612637
it binds to the `@ConfigurationProperties` beans. If you need custom type conversion you

0 commit comments

Comments
 (0)