亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

SpringCloud(第 029 篇)配置客戶端 ConfigClient 接入配置服務(wù)端

YFan / 3726人閱讀

SpringCloud(第 029 篇)配置客戶端 ConfigClient 接入配置服務(wù)端

-

一、大致介紹
1、有配置服務(wù)端,那么勢必就會有與之對應(yīng)的客戶端,SpringCloud 文檔中集成也非常簡單;
2、但是這里有點(diǎn)需要注意,就是 bootstrap 配置文件,官方建議我們在bootstrap中放置不更改的屬性,我們同樣也需要在這里做一些簡單不易于改變的配置;

3、這里還順便列舉下配置路徑的規(guī)則:
/****************************************************************************************
 * 配置服務(wù)的路勁規(guī)則:
 *
 * /{application}/{profile}[/{label}]
 * /{application}-{profile}.yml
 * /{label}/{application}-{profile}.yml
 * /{application}-{profile}.properties
 * /{label}/{application}-{profile}.properties
 ****************************************************************************************/
二、實(shí)現(xiàn)步驟 2.1 添加 maven 引用包


    4.0.0

    springms-config-client
    1.0-SNAPSHOT
    jar

    
        com.springms.cloud
        springms-spring-cloud
        1.0-SNAPSHOT
    

    
        
        
            org.springframework.cloud
            spring-cloud-starter-config
        

        
        
            org.springframework.boot
            spring-boot-starter-web
        
    

2.2 添加應(yīng)用配置文件(springms-config-clientsrcmainresourcesapplication.yml)
server:
  port: 8225


#####################################################################################################
# 測試一:配置服務(wù)客戶端Client應(yīng)用入口(正常測試 ConfigClient )
profile: profile-dev(local)
#####################################################################################################




#####################################################################################################
# 測試二:配置服務(wù)客戶端Client應(yīng)用入口(鏈接 ClientServer 測試)
#spring:
#  cloud:
#    config:
#      uri: http://localhost:8220
#      profile: dev
#      label: master #當(dāng) ConfigServer 的后端存儲的是 Git 的時候,默認(rèn)就是 master
#
#  application:
#    name: foobar  #取 foobar-dev.yml 這個文件的 application 名字,即為 foobar 名稱
#####################################################################################################





#####################################################################################################
# 測試四:配置服務(wù)客戶端Client應(yīng)用入口(鏈接 ClientServer 測試,同時本地也有一份配置文件,那么該如何抉擇呢?)
#profile: profile-local-dev
#####################################################################################################
2.3 添加 bootstrap.yml 應(yīng)用配置文件(springms-config-clientsrcmainresourcesbootstrap.yml)
#####################################################################################################
# 測試三:配置服務(wù)客戶端Client應(yīng)用入口(鏈接 ClientServer 測試)
#spring:
#  cloud:
#    config:
#      uri: http://localhost:8220
#      profile: dev
#      label: master #當(dāng) ConfigServer 的后端存儲的是 Git 的時候,默認(rèn)就是 master
#
#  application:
#    name: foobar  #取 foobar-dev.yml 這個文件的 application 名字,即為 foobar 名稱
#####################################################################################################
2.4 添加Web控制層類(springms-config-clientsrcmainjavacomspringmscloudcontrollerConfigClientController.java)
package com.springms.cloud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 配置客戶端Controller。
 *
 * @author hmilyylimh
 *
 * @version 0.0.1
 *
 * @date 2017/10/15
 *
 */
@RestController
public class ConfigClientController {

    @Value("${profile}")
    private String profile;

    @GetMapping("/profile")
    public String getProfile(){
        return this.profile;
    }
}
2.4 添加應(yīng)用啟動類(springms-config-clientsrcmainjavacomspringmscloudMsConfigClientApplication.java)
package com.springms.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * 配置客戶端ConfigClient接入配置服務(wù)端。
* * @author hmilyylimh * * @version 0.0.1 * * @date 2017/10/15 * */ @SpringBootApplication public class MsConfigClientApplication { public static void main(String[] args) { SpringApplication.run(MsConfigClientApplication.class, args); System.out.println("【【【【【【 ConfigClient微服務(wù) 】】】】】】已啟動."); } }
三、測試
/****************************************************************************************
 一、配置客戶端ConfigClient接入配置服務(wù)端(正常測試 ConfigClient ):

 1、注解:pom.xml 先刪除 configclient 的引用模塊,以便測試正常情況 ConfigClientController 接口是否暢通;
 2、編輯 application.yml 文件,注意添加 profile: profile-dev(local) 屬性;
 3、啟動 springms-config-client 模塊服務(wù),啟動1個端口;

 4、在瀏覽器輸入地址 http://localhost:8225/profile 正常情況下會輸出配置文件的內(nèi)容(內(nèi)容為:profile-dev(local));

 注意:這里還暫時不需要 bootstrap.yml 配置文件,所以測試一是不需要添加 bootstrap.yml 文件的;
 ****************************************************************************************/





/****************************************************************************************
 二、配置客戶端ConfigClient接入配置服務(wù)端(鏈接 ClientServer 測試遇到挫折):

 1、注解:pom.xml 先添加 configclient 的引用模;
 2、編輯 application.yml 文件,注意注釋 profile 屬性,然后添加相關(guān)客戶端配置;
    spring:
        cloud:
            config:
                uri: http://localhost:8220
                profile: dev
                label: master #當(dāng) ConfigServer 的后端存儲的是 Git 的時候,默認(rèn)就是 master

        application:
            name: foobar  #取 foobar-dev.yml 這個文件的 application 名字,即為 foobar 名稱
 3、啟動 springms-config-server 模塊服務(wù),啟動1個端口;
 4、啟動 springms-config-client 模塊服務(wù),啟動1個端口;

 5、然后發(fā)現(xiàn)啟動 springms-config-client 模塊出現(xiàn)錯誤,報(bào)錯信息為:Fetching config from server at: http://localhost:8888, Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/foobar/dev/master": Connection refused;
 6、發(fā)現(xiàn)錯誤信息中,為什么鏈接的是遠(yuǎn)端的 8888 端口呢?百思不得其解,難道是默認(rèn)加載的配置 8888 端口???
 7、SpringCloud里面有個“啟動上下文”,主要是用于加載遠(yuǎn)端的配置,也就是加載ConfigServer里面的配置,默認(rèn)加載順序?yàn)椋杭虞dbootstrap.*里面的配置 --> 鏈接configserver,加載遠(yuǎn)程配置 --> 加載application.*里面的配置;

 總結(jié):這里需要借助于“啟動上下文”來處理加載遠(yuǎn)程配置,請看下面環(huán)節(jié)測試三。
 ****************************************************************************************/

/****************************************************************************************
 三、配置客戶端ConfigClient接入配置服務(wù)端(鏈接 ClientServer 測試遇到挫折):

 1、注解:pom.xml 先添加 configclient 的引用模;
 2、編輯 application.yml 文件,注釋"測試二"的屬性配置;
 3、新建一個 bootstrap.yml 文件,將相關(guān)客戶端配置挪到 bootstrap.yml 文件即可;
 4、啟動 springms-config-server 模塊服務(wù),啟動1個端口;
 5、啟動 springms-config-client 模塊服務(wù),啟動1個端口;
 6、在瀏覽器輸入地址 http://localhost:8225/profile 正常情況下會輸出配置文件的內(nèi)容(內(nèi)容為:profile-dev);

 總結(jié):這里成功獲取了遠(yuǎn)端配置,并成功打印了屬性值出來,說明添加 bootstrap.yml 配置文件對我們項(xiàng)目的順利進(jìn)行起到了有效的作用。
 ****************************************************************************************/

/****************************************************************************************
 四、配置客戶端ConfigClient接入配置服務(wù)端(鏈接 ClientServer 測試,同時本地也有一份配置文件,那么該如何抉擇呢?):

 1、在測試三的基礎(chǔ)上,咱們再做點(diǎn)其它配置測試;
 2、在 application.yml 文件,再次添加 profile 屬性,看看加載的是本地配置還是遠(yuǎn)端配置?
 3、停止并重新啟動 springms-config-client 模塊服務(wù),啟動1個端口;
 4、在瀏覽器輸入地址 http://localhost:8225/profile 正常情況下會輸出遠(yuǎn)端服務(wù)的配置內(nèi)容;

 總結(jié):在ConfigServer服務(wù)啟動的時候,bootstrap 拿到遠(yuǎn)端配置注入到 profile 的屬性中的話,那么就不會再次覆蓋這個屬性了,所以只會選擇遠(yuǎn)端配置的內(nèi)容。
      那是不是會有人認(rèn)為把ConfigServer再重啟一下就行了呢?答案是不行的,因?yàn)槭走x的是遠(yuǎn)端配置內(nèi)容;
 ****************************************************************************************/
四、下載地址

https://gitee.com/ylimhhmily/SpringCloudTutorial.git

SpringCloudTutorial交流QQ群: 235322432

SpringCloudTutorial交流微信群: 微信溝通群二維碼圖片鏈接

歡迎關(guān)注,您的肯定是對我最大的支持!!!

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/67769.html

相關(guān)文章

  • SpringCloud 037 )通過bus/refresh半自動刷新ConfigClient

    摘要:添加應(yīng)用啟動類通過半自動刷新配置。配置客戶端服務(wù)想要實(shí)現(xiàn)自動刷新配置的話,一端是不要做任何處理,只需要在一端處理即可。 SpringCloud(第 037 篇)通過bus/refresh半自動刷新ConfigClient配置 - 一、大致介紹 1、上章節(jié)我們講到了手動刷新配置,但是我們假設(shè)如果微服務(wù)一多的話,那么我們是不是需要對每臺服務(wù)進(jìn)行手動刷新呢? 2、答案肯定是不需要的,我們也可...

    CloudwiseAPM 評論0 收藏0
  • SpringCloud 036 )單點(diǎn)手動動態(tài)刷新ConfigClient配置

    摘要:添加應(yīng)用啟動類單點(diǎn)手動動態(tài)刷新配置。配置客戶端服務(wù)想要實(shí)現(xiàn)自動刷新配置的話,一端是不要做任何處理,只需要在一端處理即可。 SpringCloud(第 036 篇)單點(diǎn)手動動態(tài)刷新ConfigClient配置 - 一、大致介紹 1、當(dāng)ConfigServer啟動后,假如我們新增配置內(nèi)容的話,是不是要重新啟動一下ConfigServer呢? 2、答案肯定是不需要重新啟動的,因?yàn)?Sprin...

    wanglu1209 評論0 收藏0
  • SpringCloud 035 配置服務(wù)客戶ConfigClient鏈接經(jīng)過認(rèn)證的配置服務(wù)

    SpringCloud(第 035 篇)配置服務(wù)客戶端ConfigClient鏈接經(jīng)過認(rèn)證的配置服務(wù)端 - 一、大致介紹 1、前面一章節(jié)講解了服務(wù)端配置安全認(rèn)證,那么本章節(jié)就講解如何鏈接上服務(wù)端的認(rèn)證; 2、這里還順便列舉下配置路徑的規(guī)則: /*****************************************************************************...

    klivitamJ 評論0 收藏0
  • SpringCloud 031 配置客戶ConfigClient鏈接經(jīng)過對稱加解密的配置

    摘要:添加應(yīng)用啟動類配置客戶端鏈接經(jīng)過對稱加解密的配置微服務(wù)專門為測試經(jīng)過對稱加解密的配置微服務(wù)微服務(wù)模塊。 SpringCloud(第 031 篇)配置客戶端ConfigClient鏈接經(jīng)過對稱加解密的配置微服務(wù) - 一、大致介紹 1、Git服務(wù)端的文件內(nèi)容進(jìn)行了加密處理,那么是不是配置客戶端拿到內(nèi)容之后需要解密呢? 2、答案顯然不是的,因?yàn)檫@樣解密的話,先不說實(shí)現(xiàn)起來的難易程度,單從表面...

    DDreach 評論0 收藏0
  • SpringCloud 033 配置客戶ConfigClient鏈接經(jīng)過對稱加解密的配置

    SpringCloud(第 033 篇)配置客戶端ConfigClient鏈接經(jīng)過對稱加解密的配置微服務(wù) - 一、大致介紹 1、在(第 031 篇)講解了如何鏈接對稱加密的配置服務(wù)端,而鏈接對稱非對稱加密的配置微服務(wù)也是同樣的; 2、配置客戶端不需要做什么加解密的配置,加解密的配置在服務(wù)端做就好了; 3、這里還順便列舉下配置路徑的規(guī)則: /****************************...

    ARGUS 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<