SpringBoot配置加载顺序
Externalized Configuration 优先级,序号越小优先级越高,优先级为1的会覆盖优先级为17的
- Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
@TestPropertySource
annotations on your tests.@SpringBootTest#properties
annotation attribute on your tests.- 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()). 通过
java -jar -Dkey=val ...
设置的 - OS environment variables.
- A RandomValuePropertySource that only has properties in random.*.
- Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants) yml->yaml->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).
@PropertySource
annotations on your@Configuration
classes.- Default properties (specified using SpringApplication.setDefaultProperties).
This post is licensed under CC BY 4.0 by the author.