SpringBoot配置文件的加载位置

配置文件加载位置

spring boot 启动会扫描以下位置的application.properties或者 application.yml文件作为Spring boot的默认配置文件

  1. file:./config/
  2. file:./
  3. classpath:/config/
  4. classpath:/

以上是按照优先级从高到低的顺序,所有位置的文件都会被加载,高优先级配置内容会覆盖低优先级配置内容,也可以通过配置spring.config.location来改变默认配置。

SpringBoot配置文件的加载位置

红色是file:路径,也就是项目根路径。
蓝色是classpath路径,也就是和类根目录平级的位置。