Skip to content

Commit a5338e5

Browse files
committed
Polish contribution
See gh-49835
1 parent 8f93bbf commit a5338e5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features

‎spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,6 @@ TIP: To use a reserved keyword in the name of a property, such as `my.service.im
790790

791791
NOTE: The properties that map to javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] classes available in Spring Boot, which are configured through properties files, YAML files, environment variables, and other mechanisms, are public API but the accessors (getters/setters) of the class itself are not meant to be used directly.
792792

793-
NOTE: Default values defined in javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] classes are not reflected in the javadoc:org.springframework.core.env.Environment[].
794-
If your application code references the same property using javadoc:org.springframework.beans.factory.annotation.Value[format=annotation], javadoc:org.springframework.boot.autoconfigure.condition.ConditionalOnProperty[format=annotation], or its own javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] class, it will not see the default value -- only values that are actually present in the javadoc:org.springframework.core.env.Environment[] will be applied.
795-
796793
[NOTE]
797794
====
798795
Such arrangement relies on a default empty constructor and getters and setters are usually mandatory, since binding is through standard Java Beans property descriptors, just like in Spring MVC.
@@ -855,6 +852,18 @@ TIP: To use a reserved keyword in the name of a property, such as `my.service.im
855852

856853

857854

855+
[[features.external-config.typesafe-configuration-properties.default-values]]
856+
=== Default Values
857+
858+
Default Values defined in configuration properties are not reflected in the javadoc:org.springframework.core.env.Environment[].
859+
In the examples above, the `enabled` property of `MyProperties` bound to `my.service` is `false` by default.
860+
861+
However, `my.service.enabled` is not available in the `Environment` with a value of `false` if no such property is set by the user.
862+
Concretely, this prevents you to use `@Value(${"my.service.enabled"})` or `my.service.enabled` as a placeholder in configuration properties without explicitly providing a default.
863+
If you need to query the javadoc:org.springframework.core.env.Environment[] for that property, for instance in a javadoc:org.springframework.context.annotation.Condition[] implementation, the default needs to be provided as well.
864+
865+
866+
858867
[[features.external-config.typesafe-configuration-properties.enabling-annotated-types]]
859868
=== Enabling @ConfigurationProperties-annotated Types
860869

0 commit comments

Comments
 (0)