外化配置加载顺序(写在最前面的是优先级最高的)
-
开启 DevTools 时,以~/.spring-boot-devtools.properties这个文件为准
-
测试类上的 @TestPropertySource 注解
-
@SpringBootTest#properties 属性
-
命令行参数( --server.port=9000 )
用的较多 -
SPRING_APPLICATION_JSON 中的属性
-
ServletConfig 初始化参数
-
ServletContext 初始化参数
-
java:comp/env 中的 JNDI 属性
-
System.getProperties()
用的较多 -
操作系统环境变量
用的较多 -
random.* 涉及到的 RandomValuePropertySource
-
jar 包外部的 application-{profile}.properties 或 .yml
-
jar 包内部的 application-{profile}.properties 或 .yml
-
jar 包外部的 application.properties 或 .yml
-
jar 包内部的 application.properties 或 .yml
-
@Configuration 类上的 @PropertySource
-
SpringApplication.setDefaultProperties() 设置的默认属性
application.properties
默认位置
- ./config
- ./
- CLASSPATH 中的 /config
- CLASSPATH 中的 /
springboot 会在这几个位置去寻找 application.properties 文件或者application.yml
修改名字或路径 - spring.config.name
把配置文件application.properties 的名字改为你想改的名字 - spring.config.location
把配置文件application.properties 的地址改为你想改的地址 - spring.config.additional-location
额外的地址