From 53da8da50a2cb954d507e65a7f6b6a98e6b72be4 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 26 Nov 2019 17:27:11 -0800 Subject: [PATCH] Clarify contradictory advice on the use of `@PropertySource` In general we do not recommend using @PropertySource due to them being added to the environment too late for auto-configuration to use them. This commit updates the documentation to mention them in the list of external sources along with a note. Closes gh-18900 --- .../spring-boot-docs/src/main/asciidoc/howto.adoc | 5 ----- .../src/main/asciidoc/spring-boot-features.adoc | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc index 8e093da906d3..d2658550245a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -259,11 +259,6 @@ The actual application _now_ shows the banner (as overridden by configuration) a === Change the Location of External Properties of an Application By default, properties from different sources are added to the Spring `Environment` in a defined order (see "`<>`" in the '`Spring Boot features`' section for the exact order). -A nice way to augment and modify this ordering is to add `@PropertySource` annotations to your application sources. -Classes passed to the `SpringApplication` static convenience methods and those added using `setSources()` are inspected to see if they have `@PropertySources`. -If they do, those properties are added to the `Environment` early enough to be used in all phases of the `ApplicationContext` lifecycle. -Properties added in this way have lower priority than any added by using the default locations (such as `application.properties`), system properties, environment variables, or the command line. - You can also provide the following System properties (or environment variables) to change the behavior: * `spring.config.name` (`SPRING_CONFIG_NAME`): Defaults to `application` as the root of the file name. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 36f644aa506a..af8a83a11bdd 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -351,7 +351,7 @@ Properties are considered in the following order: . <> packaged inside your jar (`application-\{profile}.properties` and YAML variants). . Application properties outside of your packaged jar (`application.properties` and YAML variants). . Application properties packaged inside your jar (`application.properties` and YAML variants). -. {spring-framework-api}/context/annotation/PropertySource.html[`@PropertySource`] annotations on your `@Configuration` classes. +. {spring-framework-api}/context/annotation/PropertySource.html[`@PropertySource`] annotations on your `@Configuration` classes (these are added late to the `Environment` and will not have any effect on anything that reads properties from the `Environment` before the `ApplicationContext` is refreshed, such as logging configuration and auto-configuration). . Default properties (specified by setting `SpringApplication.setDefaultProperties`). To provide a concrete example, suppose you develop a `@Component` that uses a `name` property, as shown in the following example: