SpringBoot配置文件加载顺序
AI-摘要
Tianli GPT
AI初始化中...
介绍自己
生成本文简介
推荐相关文章
前往主页
前往tianli博客
基础配置路径及其加载顺序
Springboot程序启动时,会从以下位置加载配置文件:
-
1.file:./config/ :当前项目下的/config目录下
-
2.file:./ :当前项目的根目录
-
3.classpath:/config/ :classpath的/config目录
-
4.classpath:/ :classpath的根目录

注意:在多个model的工程中,这种配置顺序不生效
外部配置文件加载顺序
- 开启 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() 设置的默认属性
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 leaflei
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果