天天看点

springboot 配置文件优先级springboot 配置文件优先级

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

  1. 当前目录下config/application.yaml
  2. 当前目录下application.yaml
  3. classpath下config/application.yaml
  4. classpath下application.yaml
    springboot 配置文件优先级springboot 配置文件优先级