springboot 如何加載application.properties
时间: 2023-08-06 10:06:36 浏览: 126
SpringBoot加载application.properties的过程如下:
1. 默认情况下,SpringBoot会先使用jar包根目录下的application.properties作为项目配置文件。如果存在多个配置文件,加载顺序如下:
a. config/application.properties(项目根目录中config目录下)
b. config/application.yml
c. application.properties(项目根目录下)
d. application.yml
e. resources/config/application.properties(项目resources目录中config目录下)
f. resources/config/application.yml
g. resources/application.properties(项目的resources目录下)
h. resources/application.yml
注意:如果同一个目录下同时存在application.yml和application.properties,优先读取application.properties。如果同一个配置属性在多个配置文件中都配置了,会使用第一个读取到的配置,后面读取的不会覆盖前面读取到的配置。\[2\]
2. SpringBoot在准备环境(prepareEnvironment)的过程中,会读取和加载application.properties文件,并将其存储在environment中。具体的加载过程可以参考这篇博客:https://blog.csdn.net/woshilijiuyi/article/details/82720478。\[3\]
总结起来,SpringBoot会在启动过程中自动加载application.properties文件,并根据加载顺序和优先级来确定最终使用的配置。这样可以方便地配置和管理项目的各种属性和参数。
#### 引用[.reference_title]
- *1* *3* [SpringBoot之application.properties的加载](https://blog.csdn.net/weixin_44601714/article/details/101310997)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Springboot中application.yml、application.properties和bootStrap.yml的加载顺序](https://blog.csdn.net/wounler/article/details/123853070)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![properties](https://img-home.csdnimg.cn/images/20250102104920.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)