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

SpringCloud Config分布式配置中心使用教程介紹

 更新時(shí)間:2022年12月09日 11:27:28   作者:幽默涵養(yǎng)miss u  
springcloud config是一個(gè)解決分布式系統(tǒng)的配置管理方案。它包含了 client和server兩個(gè)部分,server端提供配置文件的存儲(chǔ)、以接口的形式將配置文件的內(nèi)容提供出去,client端通過(guò)接口獲取數(shù)據(jù)、并依據(jù)此數(shù)據(jù)初始化自己的應(yīng)用

一、簡(jiǎn)介

Spring Cloud Config為分布式系統(tǒng)中的配置提供服務(wù)器端和客戶端支持??梢约泄芾硭协h(huán)境中應(yīng)用程序的配置文件。其服務(wù)器端存儲(chǔ)的默認(rèn)實(shí)現(xiàn)使用GIT。

優(yōu)勢(shì)

  • 提供服務(wù)端和客戶端支持(spring cloud config server和spring cloud config client)
  • 集中式管理分布式環(huán)境中的配置信息(所有配置文件統(tǒng)一放在了GIT倉(cāng)庫(kù)中)
  • 基于Spring環(huán)境提供配置管理,與Spring系列框架無(wú)縫結(jié)合
  • 可用于任何語(yǔ)言開(kāi)發(fā)環(huán)境,基于Http協(xié)議。
  • 默認(rèn)基于GIT倉(cāng)庫(kù)實(shí)現(xiàn)版本控制。

二、使用

1.搭建配置文件倉(cāng)庫(kù)

2.搭建Eureka-Server注冊(cè)中心服務(wù)器

3.搭建Config-Server分布式配置中心服務(wù)器

(1)導(dǎo)入依賴

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.12.RELEASE</version>
</parent>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Hoxton.SR12</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <!-- spring cloud系列技術(shù)中,唯一命名特殊的啟動(dòng)器依賴。 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
</dependencies>

(2)編寫(xiě)配置文件

server:
  port: 8888

# 增加分布式配置中心服務(wù)端配置。連接什么GIT倉(cāng)庫(kù)
spring:
  application:
    name: config-server
  cloud: # spring cloud常用配置前置
    config: # 分布式配置中心配置前置
      server: # 服務(wù)端配置
        git: # git文件倉(cāng)庫(kù)配置
          uri: https://gitee.com/bjsxt_test/config.git # git倉(cāng)庫(kù)具體地址
          #username: bjsxt_test # 私有倉(cāng)庫(kù)必須配置用戶名和密碼。
          #password: 123456789 # 公開(kāi)倉(cāng)庫(kù)可以省略用戶名和密碼配置。

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

(3)編寫(xiě)啟動(dòng)類

/**
 * EnableConfigServer - 開(kāi)啟Spring Cloud Config Server的注解。
 *  提供分布式配置中心服務(wù)端功能。
 */
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApp {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApp.class, args);
    }
}

4.搭建Config Client

Config Client對(duì)于Spring Cloud Config是客戶端,對(duì)于Eureka來(lái)說(shuō)可以是Application Server 也可以是Application Client。

(1)導(dǎo)入依賴

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <!-- spring cloud config分布式配置中心客戶端依賴 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
</dependencies>

(2)編寫(xiě)配置文件

# 新配置文件 bootstrap.yml | properties。是spring cloud config技術(shù)支持的新配置文件。
# 配置文件由config分布式配置中心客戶端讀取,并請(qǐng)求分布式配置中心服務(wù)端,查詢獲取配置文件之后,Spring Boot根據(jù)配置文件,初始化環(huán)境

spring:

  application:

    name: Config-Client
  cloud:
    config: # spring cloud config 客戶端配置
      uri: http://localhost:8888 # 分布式配置中心服務(wù)端地址。 默認(rèn)http://localhost:8888
      name: bjsxt # 要讀取的配置文件名,默認(rèn)是spring.application.name的配置值,如果沒(méi)有配置,默認(rèn)application
      profile: default # 要讀取的配置文件環(huán)境是什么,默認(rèn)default
      label: master # 要讀取的配置文件所在分支名稱。默認(rèn)null。從主干分支獲取文件。

(3)服務(wù)接口

public interface ConfigClientService {
    String test();
}

(4)服務(wù)實(shí)現(xiàn)

@Service
public class ConfigClientServiceImpl implements ConfigClientService {
    @Value("${my.content}")
    private String content;
    @Override
    public String test() {
        System.out.println("content = " + content);
        return content;
    }
}

(5)編寫(xiě)控制器

@RestController
public class ConfigClientController {
    @Autowired
    private ConfigClientService configClientService;
    @RequestMapping("/test")
    public String test(){
        return configClientService.test();
    }
}

(6)編寫(xiě)啟動(dòng)類

@SpringBootApplication
public class ConfigClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigClientApplication.class,args);
    }
}

三、熱刷新

(1)導(dǎo)入依賴(和優(yōu)雅關(guān)閉的依賴一樣)

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

(2)修改配置文件

management:
  endpoints:
    web:
      exposure:
        include: refresh,info,health

(3)修改服務(wù)實(shí)現(xiàn)(在類上添加@RefreshScope注解)

@Service
@RefreshScope
public class ConfigClientServiceImpl implements ConfigClientService {
    @Value("${my.content}")
    private String content;
    @Override
    public String test() {
        System.out.println("content = " + content);
        return content;
    }
}

(4)測(cè)試熱刷新

http://localhost:8080/actuator/refresh

四、Spring Cloud Bus(消息總線)

(1)導(dǎo)入依賴

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 總線技術(shù)中的amqp相關(guān)依賴。 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

(2)修改配置文件

spring:
  rabbitmq:
    host: 192.168.91.128
    username: bjsxt
    password: bjsxt
management:
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include: bus-refresh,info,health

(3)測(cè)試

http://localhost:8080/actuator/bus-refresh

到此這篇關(guān)于SpringCloud Config分布式配置中心使用教程介紹的文章就介紹到這了,更多相關(guān)Springcloud Config配置中心內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java和Rust實(shí)現(xiàn)JSON序列化互轉(zhuǎn)的解決方案詳解

    Java和Rust實(shí)現(xiàn)JSON序列化互轉(zhuǎn)的解決方案詳解

    這篇文章主要為大家詳細(xì)介紹了Java和Rust實(shí)現(xiàn)JSON序列化互轉(zhuǎn)的解決方案,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • 深入分析Comparable與Comparator及Clonable三個(gè)Java接口

    深入分析Comparable與Comparator及Clonable三個(gè)Java接口

    接口不是類,而是對(duì)類的一組需求描述,這些類要遵從接口描述的統(tǒng)一格式進(jìn)行定義,這篇文章主要為大家詳細(xì)介紹了Java的Comparable,Comparator和Cloneable的接口,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-05-05
  • Java List Object[]轉(zhuǎn)換成List T的實(shí)例

    Java List Object[]轉(zhuǎn)換成List T的實(shí)例

    這篇文章主要介紹了Java List Object[]轉(zhuǎn)換成List T的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • Java計(jì)算數(shù)學(xué)表達(dá)式代碼詳解

    Java計(jì)算數(shù)學(xué)表達(dá)式代碼詳解

    這篇文章主要介紹了Java計(jì)算數(shù)學(xué)表達(dá)式代碼詳解,具有一定借鑒價(jià)值,需要的朋友可以了解下。
    2017-12-12
  • Java的繪圖模式使用淺析

    Java的繪圖模式使用淺析

    這篇文章主要介紹了Java的繪圖模式使用淺析,以一個(gè)小例子大概列舉了XOR模式下能干的一些事情,需要的朋友可以參考下
    2015-10-10
  • 使用java基礎(chǔ)類實(shí)現(xiàn)zip壓縮和zip解壓工具類分享

    使用java基礎(chǔ)類實(shí)現(xiàn)zip壓縮和zip解壓工具類分享

    使用java基礎(chǔ)類寫(xiě)的一個(gè)簡(jiǎn)單的zip壓縮解壓工具類,實(shí)現(xiàn)了指定目錄壓縮到和該目錄同名的zip文件和將zip文件解壓到指定的目錄的功能
    2014-03-03
  • shiro無(wú)狀態(tài)web集成的示例代碼

    shiro無(wú)狀態(tài)web集成的示例代碼

    本篇文章主要介紹了shiro無(wú)狀態(tài)web集成的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-09-09
  • 一文搞懂接口參數(shù)簽名與驗(yàn)簽(附含java python php版)

    一文搞懂接口參數(shù)簽名與驗(yàn)簽(附含java python php版)

    這篇文章主要為大家介紹了java python php不同版的接口參數(shù)簽名與驗(yàn)簽示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • Java中的volatile關(guān)鍵字原理深入解析

    Java中的volatile關(guān)鍵字原理深入解析

    這篇文章主要介紹了Java中的volatile關(guān)鍵字原理深入解析,volatile是Java 編程語(yǔ)言允許線程訪問(wèn)共享變量,為了確保共享變量能被準(zhǔn)確和一致地更新,線程應(yīng)該確保通過(guò)排他鎖單獨(dú)獲得這個(gè)變量,需要的朋友可以參考下
    2023-12-12
  • java的GUI實(shí)現(xiàn)簡(jiǎn)單切換界面

    java的GUI實(shí)現(xiàn)簡(jiǎn)單切換界面

    這篇文章主要為大家詳細(xì)介紹了java的GUI實(shí)現(xiàn)簡(jiǎn)單切換界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04

最新評(píng)論

北川| 华坪县| 会宁县| 乐昌市| 布拖县| 龙州县| 兰州市| 满洲里市| 时尚| 临高县| 武义县| 南京市| 寿阳县| 洱源县| 乐至县| 定远县| 佛山市| 怀远县| 东乡| 揭东县| 邳州市| 荣昌县| 沅陵县| 永康市| 华坪县| 鲜城| 永康市| 通山县| 内丘县| 依兰县| 廉江市| 孝昌县| 太保市| 青铜峡市| 饶阳县| 寿宁县| 临猗县| 天峨县| 桃江县| 山阳县| 南投县|