来源:spring.io
由上至下优先级依次提升(下方覆盖上方)
- Default properties (specified by setting
SpringApplication.setDefaultProperties). @PropertySourceannotations on your@Configurationclasses. Please note that such property sources are not added to theEnvironmentuntil the application context is being refreshed. This is too late to configure certain properties such aslogging.*andspring.main.*which are read before refresh begins.- Config data (such as
application.propertiesfiles). - A
RandomValuePropertySourcethat has properties only inrandom.*. - OS environment variables.
- Java System properties (
System.getProperties()). - JNDI attributes from
java:comp/env. ServletContextinit parameters.ServletConfiginit parameters.- Properties from
SPRING_APPLICATION_JSON(inline JSON embedded in an environment variable or system property). - Command line arguments.
propertiesattribute on your tests. Available on@SpringBootTestand the test annotations for testing a particular slice of your application.@TestPropertySourceannotations on your tests.- Devtools global settings properties in the
$HOME/.config/spring-bootdirectory when devtools is active.
Config data files are considered in the following order:
- Application properties packaged inside your jar (
application.propertiesand YAML variants). - Profile-specific application properties packaged inside your jar (
application-{profile}.propertiesand YAML variants). - Application properties outside of your packaged jar (
application.propertiesand YAML variants). - Profile-specific application properties outside of your packaged jar (
application-{profile}.propertiesand YAML variants).