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
@ -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 "`<<spring-boot-features.adoc#boot-features-external-config>>`" 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.
@ -351,7 +351,7 @@ Properties are considered in the following order:
. <<boot-features-external-config-profile-specific-properties,Profile-specific application properties>> 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: