📊 配置加载的优先级顺序(完整列表)
Spring Boot 按照以下顺序加载配置(后面的会覆盖前面的):
优先级从低到高(数字越大优先级越高):
- 默认属性(SpringApplication.setDefaultProperties)
- @Configuration 类上的 @PropertySource
- 配置文件(application.properties/yml)
3.1. jar 包内的 application.properties
3.2. jar 包内的 application-{profile}.properties
3.3. jar 包外的 application.properties
3.4. jar 包外的 application-{profile}.properties - RandomValuePropertySource(random.* 属性)
- 操作系统环境变量
- Java 系统属性(System.getProperties())
- JNDI 属性(java:comp/env)
- ServletContext 初始化参数
- ServletConfig 初始化参数
- SPRING_APPLICATION_JSON 中的属性
- 命令行参数
- @TestPropertySource 注解(测试时)