springboot 配置文件优先级
一、配置优先级
1. @TestPropertySource 注解
2. 命令行参数
3. Java系统属性(System.getProperties())
4. 操作系统环境变量
5. 只有在random.*里包含的属性会产生一个RandomValuePropertySource
6. 在打包的jar外的应用程序配置文件(application.properties,包含YAML和profile变量)
7. 在打包的jar内的应用程序配置文件(application.properties,包含YAML和profile变量)
8. 在@Configuration类上的@PropertySource注解
9. 默认属性(使用SpringApplication.setDefaultProperties指定)
二、.properties和.yaml 方式
.properties同等下优先于yaml
- 当前目录下config/application.yaml
- 当前目录下application.yaml
- classpath下config/application.yaml
- classpath下application.yaml
springboot 配置文件优先级springboot 配置文件优先级