javascript
SpringBoot 配置文件bootstrap和application的区别
目錄
- 一、SpringBoot配置文件
- 二、bootstrap和application區(qū)別
- 三、bootstrap和application的應(yīng)用場(chǎng)景
一、SpringBoot配置文件
-
bootstrap(.yml 或者 .properties)
-
application(.yml 或者 .properties)
二、bootstrap和application區(qū)別
特意去翻了下 Spring Boot 的官方文檔,沒(méi)有找到關(guān)于這兩種文件的具體定義,然后再翻了下 Spring Cloud 的官方文檔找到了它們的區(qū)別。
https://cloud.spring.io/spring-cloud-static/Greenwich.SR1/single/spring-cloud.html#_the_bootstrap_application_context
Spring Cloud 構(gòu)建于 Spring Boot 之上,在 Spring Boot 中有兩種上下文,一種是 bootstrap,另外一種是 application,bootstrap 是應(yīng)用程序的父上下文,也就是說(shuō) bootstrap 加載優(yōu)先于 applicaton。
bootstrap 主要用于從額外的資源來(lái)加載配置信息,還可以在本地外部配置文件中解密屬性。這兩個(gè)上下文共用一個(gè)環(huán)境,它是任何Spring應(yīng)用程序的外部屬性的來(lái)源。bootstrap 里面的屬性會(huì)優(yōu)先加載,它們默認(rèn)也不能被本地相同配置覆蓋。
對(duì)比 application 配置文件,bootstrap 配置文件具有以下幾個(gè)特性。
-
boostrap 由父 ApplicationContext 加載,比 applicaton 優(yōu)先加載;
-
boostrap 里面的屬性不能被覆蓋;
三、bootstrap和application的應(yīng)用場(chǎng)景
application
- 主要用于spring boot 項(xiàng)目的自動(dòng)化配置;
bootstrap
-
a、使用 spring Cloud config 配置中心時(shí),這時(shí)需要在 bootstrap 配置文件中添加連接到配置中心的配置屬性來(lái)加載外部配置中心的配置信息;
-
b、一些固定的不能被覆蓋的配置;
-
c、一些加密/解密的場(chǎng)景;
總結(jié)
以上是生活随笔為你收集整理的SpringBoot 配置文件bootstrap和application的区别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: etf基金怎么买卖怎么操作 etf基金如
- 下一篇: SpringBoot 集成 Nacos