spring boot 配置加载顺序
时间: 2023-04-19 15:00:46 浏览: 158
Spring Boot 配置加载顺序如下:
1. 命令行参数:可以通过命令行参数来指定配置文件的位置,例如:java -jar myproject.jar --spring.config.location=/path/to/application.properties。
2. SPRING_APPLICATION_JSON:可以通过环境变量 SPRING_APPLICATION_JSON 来指定 JSON 格式的配置信息。
3. ServletConfig 初始化参数:可以通过 ServletConfig 的初始化参数来指定配置文件的位置。
4. ServletContext 初始化参数:可以通过 ServletContext 的初始化参数来指定配置文件的位置。
5. java:comp/env JNDI 属性:可以通过 JNDI 属性来指定配置文件的位置。
6. 系统环境变量:可以通过系统环境变量来指定配置文件的位置。
7. RandomValuePropertySource:可以通过 RandomValuePropertySource 来指定随机值。
8. jar 包外部的 application-{profile}.properties 或 application.yml 配置文件。
9. jar 包内部的 application-{profile}.properties 或 application.yml 配置文件。
10. jar 包外部的 application.properties 或 application.yml 配置文件。
11. jar 包内部的 application.properties 或 application.yml 配置文件。
其中,数字越小的优先级越高。如果同一级别下有多个配置文件,后加载的会覆盖先加载的。
阅读全文
相关推荐


















