加载属性文件位置与优先级

@SpringBootApplication
public class BootConfigApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(BootConfigApplication.class, args);
        ConfigurableEnvironment environment = context.getEnvironment();
        String locationIpDir = environment.getProperty("location.ip.dir");
        String curDir = environment.getProperty("user.dir");
        System.out.println(locationIpDir + "," + curDir);
        context.close();
    }
}
规则一

file:./config/application.properties 当前项目路径config目录下
file:./application.properties] 当前项目路径下
classpath:/config/application.properties 类路径config目录下
classpath:/application.properties 类路径下

规则二

xxx.properties 和 xxx.yml 两中配置文件同时存在时,优先级 .properties >.yml ,同一目录文件里面没有.properties文件 则读取.yml 文件
SpringBoot - 1.加载属性文件位置与优先级
SpringBoot - 1.加载属性文件位置与优先级
SpringBoot - 1.加载属性文件位置与优先级

代码跟踪,Debug

SpringBoot - 1.加载属性文件位置与优先级SpringBoot - 1.加载属性文件位置与优先级SpringBoot - 1.加载属性文件位置与优先级

相关文章:

  • 2021-07-30
  • 2021-08-07
  • 2022-12-23
  • 2021-06-26
  • 2021-10-03
  • 2021-09-02
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2021-11-17
  • 2021-06-28
  • 2022-12-23
  • 2022-01-19
  • 2021-04-18
  • 2022-12-23
相关资源
相似解决方案