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

SpringCloud2020 bootstrap 配置文件失效的解決方法

 更新時間:2021年02月07日 08:56:24   作者:馮文議  
這篇文章主要介紹了SpringCloud2020 bootstrap 配置文件失效的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

Spring Cloud 2020版本 bootstrap 配置文件(properties 或者 yml)無效

如何解決?

背景介紹

微服務(wù)是基于Spring Cloud框架搭建的,Spring Cloud Config作為服務(wù)配置中心。

業(yè)務(wù)服務(wù)只配置服務(wù)名稱、啟用環(huán)境和config的URL地址,其他都配置在配置中心,例如服務(wù)端口、服務(wù)注冊中心地址等??稍陂_發(fā)環(huán)境(dev)、測試環(huán)境(test)和生產(chǎn)環(huán)境(prod)分別配置。

所以預(yù)想的啟動流程是:先加載配置文件,再啟動服務(wù)。

之前的做法是,將配置文件名稱改為:bootstrap.properties。

問題

之前直接就可以用,而現(xiàn)在,啟動的端口是8080,明顯沒有加載到bootstrap.properties文件,我以為我的文件名字寫錯了,核對了幾次,確認(rèn)無誤,我猜想估計(jì)是bootstramp.properties配置文件沒有生效。

之前的版本:

  • spring boot 2.3.1.RELEASE
  • spring cloud Hoxton.SR4

當(dāng)前版本:

  • spring boot 2.4.2
  • spring cloud 2020.0.1

查找原因

根據(jù)上面出現(xiàn)的問題,我使用百度搜索了下,大概的原因知道了:從Spring Boot 2.4版本開始,配置文件加載方式進(jìn)行了重構(gòu)。

另外也有配置的默認(rèn)值變化,如下:

Spring Boot 2.3.8.RELEASE

package org.springframework.cloud.bootstrap;
public class BootstrapApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
 public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
  ConfigurableEnvironment environment = event.getEnvironment();
  if ((Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, true)) {

Spring Boot 2.4.2

package org.springframework.cloud.util;
public abstract class PropertyUtils {
 public static boolean bootstrapEnabled(Environment environment) {
  return (Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, false) || MARKER_CLASS_EXISTS;
 }

傳統(tǒng)解決方案

其實(shí)官網(wǎng)說得很明白。看下面這段:

Config First Bootstrap
To use the legacy bootstrap way of connecting to Config Server, bootstrap must be enabled via a property or the spring-cloud-starter-bootstrap starter. The property is spring.cloud.bootstrap.enabled=true. It must be set as a System Property or environment variable. Once bootstrap has been enabled any application with Spring Cloud Config Client on the classpath will connect to Config Server as follows: When a config client starts, it binds to the Config Server (through the spring.cloud.config.uri bootstrap configuration property) and initializes Spring Environment with remote property sources.

The net result of this behavior is that all client applications that want to consume the Config Server need a bootstrap.yml (or an environment variable) with the server address set in spring.cloud.config.uri (it defaults to "http://localhost:8888").

兩個關(guān)鍵點(diǎn):

1、加一個依賴:spring-cloud-starter-bootstrap

<dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

2、加一個配置:spring.cloud.config.uri

bootstrap.properties

# 應(yīng)用名稱
spring.application.name=erwin-cloud-user
# 啟用環(huán)境
spring.profiles.active=dev

# 配置文件
spring.cloud.config.label=${spring.application.name}
spring.cloud.config.name=${spring.application.name}
spring.cloud.config.profile=${spring.profiles.active}
spring.cloud.config.uri=http://localhost:9000

解決方案

現(xiàn)在,你只需要這樣:

application.properties

# 應(yīng)用名稱
spring.application.name=erwin-cloud-user
# 啟用環(huán)境
spring.profiles.active=dev

spring.config.import=optional:configserver:http://localhost:9000

spring.cloud.config.label=${spring.application.name}
spring.cloud.config.name=${spring.application.name}
spring.cloud.config.profile=${spring.profiles.active}

到此這篇關(guān)于SpringCloud2020 bootstrap 配置文件失效的解決方法的文章就介紹到這了,更多相關(guān)SpringCloud2020 bootstrap 配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring如何自定義XML配置擴(kuò)展

    Spring如何自定義XML配置擴(kuò)展

    這篇文章主要介紹了Spring如何自定義XML配置擴(kuò)展,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-12-12
  • java中把漢字轉(zhuǎn)換成簡拼的實(shí)現(xiàn)代碼

    java中把漢字轉(zhuǎn)換成簡拼的實(shí)現(xiàn)代碼

    本篇文章是對在java中把漢字轉(zhuǎn)換成簡拼的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Java幾個重要的關(guān)鍵字詳析

    Java幾個重要的關(guān)鍵字詳析

    這篇文章主要介紹了Java幾個重要的關(guān)鍵字詳析,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考一下,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助
    2022-07-07
  • Spring Boot 啟動、停止、重啟、狀態(tài)腳本

    Spring Boot 啟動、停止、重啟、狀態(tài)腳本

    今天給大家分享Spring Boot 項(xiàng)目腳本(啟動、停止、重啟、狀態(tài)),通過示例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2021-06-06
  • Java如何對方法進(jìn)行調(diào)用詳解

    Java如何對方法進(jìn)行調(diào)用詳解

    今天給大家整理了Java如何對方法進(jìn)行調(diào)用,文中有非常詳細(xì)的介紹及代碼示例,對正在學(xué)習(xí)java的小伙伴們很有幫助,需要的朋友可以參考下
    2021-06-06
  • ???????Spring多租戶數(shù)據(jù)源管理 AbstractRoutingDataSource

    ???????Spring多租戶數(shù)據(jù)源管理 AbstractRoutingDataSource

    本文技術(shù)了???????Spring多租戶數(shù)據(jù)源管理 AbstractRoutingDataSource,下文詳細(xì)內(nèi)容介紹,需要的小伙伴可以參考一下
    2022-05-05
  • 解決logback-classic 使用testCompile的打包問題

    解決logback-classic 使用testCompile的打包問題

    這篇文章主要介紹了解決logback-classic 使用testCompile的打包問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Java設(shè)計(jì)模式之責(zé)任鏈模式詳解

    Java設(shè)計(jì)模式之責(zé)任鏈模式詳解

    客戶端發(fā)出一個請求,鏈上的對象都有機(jī)會來處理這一請求,而客戶端不需要知道誰是具體的處理對象。這樣就實(shí)現(xiàn)了請求者和接受者之間的解耦,并且在客戶端可以實(shí)現(xiàn)動態(tài)的組合職責(zé)鏈。使編程更有靈活性
    2022-07-07
  • springboot實(shí)現(xiàn)增加黑名單和白名單功能

    springboot實(shí)現(xiàn)增加黑名單和白名單功能

    本文主要介紹了springboot實(shí)現(xiàn)增加黑名單和白名單功能,就是單純的實(shí)現(xiàn)filter,然后注冊到springboot里面,在filter里面進(jìn)行黑白名單的篩選,感興趣的可以了解一下
    2024-05-05
  • 淺談Java線程Thread.join方法解析

    淺談Java線程Thread.join方法解析

    本篇文章主要介紹了淺談Java線程Thread.join方法解析,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01

最新評論

买车| 湾仔区| 东光县| 吴川市| 吉林市| 炎陵县| 南投市| 宜宾县| 望城县| 疏勒县| 建始县| 龙游县| 巢湖市| 英德市| 兰考县| 灯塔市| 鄯善县| 吉首市| 咸宁市| 石楼县| 黑水县| 通许县| 论坛| 华宁县| 来凤县| 台安县| 庆城县| 丰城市| 朔州市| 兴山县| 沙雅县| 朝阳市| 武威市| 新密市| 罗甸县| 嘉兴市| 隆德县| 舒城县| 钟祥市| 禄丰县| 贵南县|