最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于SpringBoot bootstrap.yml配置未生效的解決

 更新時(shí)間:2020年10月08日 08:47:06   作者:JustPlay1994  
這篇文章主要介紹了基于SpringBoot bootstrap.yml配置未生效的解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

我就廢話不多說了,大家還是直接看代碼吧~

<!--需要引入該jar才能使bootstrap配置文件生效-->
 <dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-context</artifactId>
 </dependency>

補(bǔ)充知識(shí):SpringBoot不讀取bootstrap.yml/properties文件

今天寫創(chuàng)建了一個(gè)SpringBoot項(xiàng)目,配置文件從其他項(xiàng)目拷貝了一份bootstrap.yml

之前一直用的application.yml

心想:application.yml 優(yōu)先級(jí)沒有bootstrap.yml 高,bootstrap配置文件肯定沒問題

項(xiàng)目一跑來,發(fā)現(xiàn)配置文件里面的內(nèi)容沒讀取到。

之后通過各種查資料,才明白了application.yml 和bootstrap.yml 的區(qū)別,不僅僅是優(yōu)先級(jí)的問題。

先說我的問題是什么原因吧:

SpringBoot 項(xiàng)目中如果沒有依賴 spring-cloud-context 的話,是不會(huì)讀取bootstrap.properties 文件

也就是說

bootstrap.yml配置是SpringCloud項(xiàng)目才會(huì)用到的。

如果你的項(xiàng)目?jī)H僅是一個(gè)SpringBoot項(xiàng)目,只會(huì)識(shí)別application.yml配置文件。

由于SpringCloud是基于SpringBoot構(gòu)建的,所有SpringCloud項(xiàng)目?jī)煞N文件都會(huì)識(shí)別,這個(gè)時(shí)候才有優(yōu)先級(jí)的說法,SpringCloud項(xiàng)目是會(huì)優(yōu)先讀取bootstrap配置在讀取application配置。

引用Spring官網(wǎng)的一句話

A Spring Cloud application operates by creating a “bootstrap” context, which is a parent context for the main application. Out of the box it is responsible for loading configuration properties from the external sources, and also decrypting properties in the local external configuration files.

SpringCloud 應(yīng)用是基于 一個(gè) “bootstrap”的上下文運(yùn)行的。

也就說明了 bootstrap這個(gè)配置是SpringCloud 應(yīng)用才會(huì)用的。

而且這個(gè)配置是不能被覆蓋的,也就是優(yōu)先級(jí)比application配置中的高。

什么配置在application配置?什么配置在bootstrap里面配置?

1、當(dāng)使用 Spring Cloud Config Server 的時(shí)候,spring.application.name 和 spring.cloud.config.server.git.uri應(yīng)該在 bootstrap.yml 里面指定

2、一些加密解密的配置也應(yīng)該配置在bootstrap里面

英文好的可以參考官網(wǎng)文章:

https://cloud.spring.io/spring-cloud-commons/multi/multi__spring_cloud_context_application_context_services.html#customizing-bootstrap-properties

以上這篇基于SpringBoot bootstrap.yml配置未生效的解決就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

土默特右旗| 高邑县| 揭东县| 清水河县| 德清县| 华安县| 泰安市| 贞丰县| 淄博市| 西乌珠穆沁旗| 开平市| 泸州市| 武宁县| 卢龙县| 水富县| 崇左市| 花垣县| 株洲市| 嵊泗县| 丰原市| 沾益县| 嘉禾县| 奉贤区| 德钦县| 满洲里市| 勐海县| 通河县| 丹巴县| 延津县| 东辽县| 都昌县| 台江县| 邮箱| 平阳县| 钟祥市| 晋城| 宁德市| 宾阳县| 会泽县| 韩城市| 阿勒泰市|