轉:https://blog.csdn.net/zl1zl2zl3/article/details/83716564
1、Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
2、@TestPropertySource annotations on your tests.
3、@SpringBootTest#properties annotation attribute on your tests.
4、Command line arguments.
5、Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
6、ServletConfig init parameters.
7、ServletContext init parameters.
8、JNDI attributes from java:comp/env.
9、Java System properties (System.getProperties()).
10、OS environment variables.
11、A RandomValuePropertySource that only has properties in random.*.
12、Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
13、Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
14、Application properties outside of your packaged jar (application.properties and YAML variants).
15、Application properties packaged inside your jar (application.properties and YAML variants).
16、@PropertySource annotations on your @Configuration classes.
17、Default properties (specified using SpringApplication.setDefaultProperties).
spring boot配置屬性加載順序:
1、開發者工具 `Devtools` 全局配置參數;
2、單元測試上的 `@TestPropertySource` 注解指定的參數;
3、單元測試上的 `@SpringBootTest` 注解指定的參數;
4、命令行指定的參數,如 `java -jar springboot.jar --name="Java技術棧"`;
5、命令行中的 `SPRING_APPLICATION_JSON` 指定參數, 如 `java -Dspring.application.json='{"name":"Java技術棧"}' -jar springboot.jar`
6、`ServletConfig` 初始化參數;
7、`ServletContext` 初始化參數;
8、JNDI參數(如 `java:comp/env/spring.application.json`);
9、Java系統參數(來源:`System.getProperties()`);
10、操作系統環境變量參數;
11、`RandomValuePropertySource` 隨機數,僅匹配:`ramdom.*`;
12、JAR包外面的配置文件參數(`application-{profile}.properties(YAML)`)
13、JAR包里面的配置文件參數(`application-{profile}.properties(YAML)`)
14、JAR包外面的配置文件參數(`application.properties(YAML)`)
15、JAR包里面的配置文件參數(`application.properties(YAML)`)
16、`@Configuration`配置文件上 `@PropertySource` 注解加載的參數;
17、默認參數(通過 `SpringApplication.setDefaultProperties` 指定);