官方文档奉上:
24. Externalized Configuration
--------官网内容--------
- Devtools global settings properties on your home directory (
~/.spring-boot-devtools.properties
when devtools is active).- @TestPropertySource annotations on your tests.
properties
attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.- Command line arguments.
- Properties from
SPRING_APPLICATION_JSON
(inline JSON embedded in an environment variable or system property).ServletConfig
init parameters.ServletContext
init parameters.- JNDI attributes from
java:comp/env
.- Java System properties (
System.getProperties()
).- OS environment variables.
- A
RandomValuePropertySource
that has properties only inrandom.*
.- Profile-specific application properties outside of your packaged jar (
application-{profile}.properties
and YAML variants).- 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).- @PropertySource annotations on your
@Configuration
classes. Please note that such property sources are not added to theEnvironment
until the application context is being refreshed. This is too late to configure certain properties such aslogging.*
andspring.main.*
which are read before refresh begins.- Default properties (specified by setting
SpringApplication.setDefaultProperties
)
1. Devtools全局配置
2. 测试环境 @TestPropertySource 注解
3. 测试环境 properties
属性
4. 启动的命令行参数
5. SPRING_APPLICATION_JSON
的属性
6. ServletConfig
初始化参数
7. ServletContext
初始化参数
8. JNDI属性
9. Java系统属性
10. OS环境变量
11. RandomValuePropertySource
随机值属性
12. jar包外的application-{profile}.properties属性 (profile是做文件过滤的)
13. jar包内的application-{profile}.properties属性
14. jar包外的application.properties属性
15. jar包内的application.properties属性
16. @PropertySource 注解绑定
17. 默认属性 (SpringApplication.setDefaultProperties
)