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

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

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

一、簡介

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

優(yōu)勢

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

二、使用

1.搭建配置文件倉庫

2.搭建Eureka-Server注冊中心服務(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ù)中,唯一命名特殊的啟動器依賴。 -->
    <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)編寫配置文件

server:
  port: 8888

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

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

(3)編寫啟動類

/**
 * EnableConfigServer - 開啟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對于Spring Cloud Config是客戶端,對于Eureka來說可以是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)編寫配置文件

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

spring:

  application:

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

(3)服務(wù)接口

public interface ConfigClientService {
    String test();
}

(4)服務(wù)實現(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)編寫控制器

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

(6)編寫啟動類

@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ù)實現(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)測試熱刷新

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)測試

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

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

相關(guān)文章

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

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

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

    深入分析Comparable與Comparator及Clonable三個Java接口

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

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

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

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

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

    Java的繪圖模式使用淺析

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

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

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

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

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

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

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

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

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

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

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

最新評論

昭平县| 邛崃市| 仁寿县| 鹿泉市| 鹿泉市| 社旗县| 盖州市| 来安县| 建阳市| 盖州市| 安义县| 洛川县| 南平市| 桐庐县| 乌恰县| 滕州市| 武威市| 怀柔区| 同心县| 绿春县| 金沙县| 门源| 潼关县| 枣阳市| 丹东市| 延川县| 平武县| 大竹县| 罗平县| 三门县| 汤阴县| 陆川县| 湖南省| 新源县| 都匀市| 进贤县| 会泽县| 新昌县| 黔东| 桃江县| 察雅县|