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

SpringCloud微服務(wù)之Config知識總結(jié)

 更新時間:2021年05月19日 17:17:47   作者:ProChick  
今天帶大家學(xué)習(xí)SpringCloud微服務(wù)中的Config的相關(guān)知識,文中有非常詳細的介紹,對正在學(xué)習(xí)SpringCloud微服務(wù)的小伙伴們有很好地幫助,需要的朋友可以參考下

一、什么是Spring Cloud Config?

  • Spring Cloud Config 可以為微服務(wù)架構(gòu)中的應(yīng)用提供集中化的外部配置支持,它分為服務(wù)端和客戶端兩個部分。
  • Spring Cloud Config 服務(wù)端被稱為分布式配置中心,它是個獨立的應(yīng)用,可以從配置倉庫獲取配置信息并提供給客戶端使用。
  • Spring Cloud Config 客戶端可以通過配置中心來獲取配置信息,在啟動時加載配置。
  • Spring Cloud Config 的配置中心默認采用Git來存儲配置信息,所以天然就支持配置信息的版本管理,并且可以使用Git客戶端來方便地管理和訪問配置信息。

二、搭建GIT環(huán)境

創(chuàng)建倉庫

在這里插入圖片描述

創(chuàng)建文件

  • master分支
# config-dev.yml
config:
  info: "config info for dev(master)"
# config-test.yml
config:
  info: "config info for test(master)"
# config-prod.yml
config:
  info: "config info for prod(master)"
  • dev分支
# config-dev.yml
config:
  info: "config info for dev(dev)"
# config-test.yml
config:
  info: "config info for test(dev)"
# config-prod.yml
config:
  info: "config info for prod(dev)"

三、服務(wù)端示例

添加依賴

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>2.2.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
    <version>2.2.0.RELEASE</version>
</dependency>

添加配置

  • 啟動類
@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class SpringcloudConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringcloudConfigServerApplication.class, args);
    }
}
  • application.yml配置文件
server:
  port: 8888
spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        # 配置存儲配置信息的Git倉庫
        git:
          uri: https://gitee.com/prochick/spring-cloud-config.git
          # Git用戶名
          username: xxx
          # Git密碼
          password: xxx
          # 指定是否開啟啟動時直接從git獲取配置
          clone-on-start: true

eureka:
  instance:
    prefer-ip-address: true
    instance-id: config-server-8888
  client:
    fetch-registry: false
    register-with-eureka: true
    service-url:
      defaultZone: http://localhost:8010/eureka/

訪問說明

# 獲取配置信息
/{label}/{application}-{profile}
# 獲取配置文件信息
/{label}/{application}-{profile}.yml
  • application

代表應(yīng)用名稱,默認為配置文件中的spring.application.name,如果配置了spring.cloud.config.name,則為該名稱

  • label

代表分支名稱,對應(yīng)配置文件中的spring.cloud.config.label

  • profile

代表環(huán)境名稱,對應(yīng)配置文件中的spring.cloud.config.profile

測試使用

# 訪問http://localhost:8888/master/config-dev來獲取master分支上dev環(huán)境的配置信息
# 訪問http://localhost:8888/master/config-dev.yml來獲取master分支上dev環(huán)境的配置文件信息
# 訪問http://localhost:8888/master/config-test.yml來獲取master分支上test環(huán)境的配置文件信息
# 訪問http://localhost:8888/dev/config-dev.yml來獲取dev分支上dev環(huán)境的配置文件信息

四、客戶端示例

添加依賴

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<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>
    <version>2.2.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
    <version>2.2.0.RELEASE</version>
</dependency>

添加配置

  • 配置文件

bootstrap.yml

server:
  port: 9999
spring:
  application:
    name: config-client

  cloud:
    config:
      # 配置中心地址
      uri: http://localhost:8888
      # 分支名稱
      label: master
      # 配置文件名稱
      name: config
      # 配置后綴名稱
      profile: dev

eureka:
  instance:
    prefer-ip-address: true
    instance-id: config-client-9999
    client:
      fetch-registry: false
      register-with-eureka: true
      service-url:
        defaultZone: http://localhost:8010/eureka/
 
# 暴露刷新監(jiān)控 
management:
  endpoints:
    web:
      exposure:
        include: 'refresh'

控制器類

@RestController
@RefreshScope
public class ConfigController {

    @Value("${config.info}")
    private String configInfo;

    @GetMapping("/configInfo")
    public String getConfigInfo() {

        return configInfo;
    }
}

測試使用

# 訪問http://localhost:9999/configInfo 可以獲取到dev分支下dev環(huán)境的配置

五、安全認證示例

添加依賴

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
    <version>2.2.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

添加配置

  • 服務(wù)端配置
server:
  port: 8888
spring:
  application:
    name: config-server
  # 配置存儲配置信息的Git倉庫
  cloud:
    config:
      server:
        git:
          # 訪問地址
          uri: https://gitee.com/prochick/spring-cloud-config.git
          # Git用戶名
          username: xxx
          # Git密碼
          password: xxx
          # 指定是否開啟啟動時直接從git獲取配置
          clone-on-start: true
  # 配置用戶名和密碼
  security: 
    user:
      name: xxx
      password: xxx
  • 客戶端配置
server:
  port: 9999
spring:
  application:
    name: config-client

  cloud:
    config:
      # 配置中心地址
      uri: http://localhost:8888
      # 分支名稱
      label: master
      # 配置文件名稱
      name: config
      # 配置后綴名稱
      profile: dev
      # 配置中心用戶名
      username: xxx
      # 配置中心密碼
      password: xxx

六、集群搭建示例

添加配置

bootstrap.yml

server:
  port: 9999
spring:
  application:
    name: config-client

  cloud:
    config:
      # 分支名稱
      label: master
      # 配置文件名稱
      name: config
      # 配置后綴名稱
      profile: dev
      # 集群綁定
      discovery:
        enabled: true
        service-id: config-server

eureka:
  instance:
    prefer-ip-address: true
    instance-id: config-client-9999
    client:
      fetch-registry: true
      register-with-eureka: true
      service-url:
        defaultZone: http://localhost:8010/eureka/

測試訪問

# 訪問eureka-server

在這里插入圖片描述

# 訪問http://localhost:9999/configInfo 可以獲取到dev分支下dev環(huán)境的配置

到此這篇關(guān)于SpringCloud微服務(wù)之Config知識總結(jié)的文章就介紹到這了,更多相關(guān)SpringCloud Config內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Tomcat數(shù)據(jù)源配置方法_JBuilder中

    Tomcat數(shù)據(jù)源配置方法_JBuilder中

    今天幫一同事配置一個數(shù)據(jù)源,采用tomcat5.5.9,本來是個很簡單的事,以前也配過,但由于很長時間沒用過容器提供的數(shù)據(jù)源了(IOC用慣了),也只記的個大概了,所以剛開始一配就出錯了,google了一下,有很多資料,照著試試卻都不好使(到不是別人說的不對,只是大家用的版本不同)。
    2008-10-10
  • SpringBoot詳解整合Redis緩存方法

    SpringBoot詳解整合Redis緩存方法

    本文主要介紹了SpringBoot整合Redis緩存的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • JAVA拋出異常的三種形式詳解

    JAVA拋出異常的三種形式詳解

    這篇文章主要介紹了JAVA拋出異常的三種形式詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-07-07
  • spring與disruptor集成的簡單示例

    spring與disruptor集成的簡單示例

    本篇文章主要介紹了spring與disruptor集成的簡單示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • Java使用橋接模式實現(xiàn)開關(guān)和電燈照明功能詳解

    Java使用橋接模式實現(xiàn)開關(guān)和電燈照明功能詳解

    這篇文章主要介紹了Java使用橋接模式實現(xiàn)開關(guān)和電燈照明功能,較為詳細的講述了橋接模式的概念、原理并結(jié)合實例形式分析了Java使用橋接模式實現(xiàn)開關(guān)和電燈照明功能相關(guān)操作步驟與注意事項,需要的朋友可以參考下
    2018-05-05
  • SpringBoot整合Mongodb實現(xiàn)增刪查改的方法

    SpringBoot整合Mongodb實現(xiàn)增刪查改的方法

    這篇文章主要介紹了SpringBoot整合Mongodb實現(xiàn)簡單的增刪查改,MongoDB是一個以分布式數(shù)據(jù)庫為核心的數(shù)據(jù)庫,因此高可用性、橫向擴展和地理分布是內(nèi)置的,并且易于使用。況且,MongoDB是免費的,開源的,感興趣的朋友跟隨小編一起看看吧
    2022-05-05
  • springboot項目打包發(fā)布部署的過程及jar和war的區(qū)別

    springboot項目打包發(fā)布部署的過程及jar和war的區(qū)別

    Spring Boot使用了內(nèi)嵌容器,因此它的部署方式也變得非常簡單靈活,可以將Spring Boot項目打包成JAR包來獨立運行,Spring Boot項目既可以生成WAR包發(fā)布,也可以生成JAR包發(fā)布,那么它們有什么區(qū)別呢
    2022-11-11
  • SpringBoot @Import與@Conditional注解使用詳解

    SpringBoot @Import與@Conditional注解使用詳解

    在了解spring boot自動配置原理前,再來了解下兩個注解@Import注解和@Conditional注解,@Conditional是Spring4新提供的注解,它的作用是按照一定的條件進行判斷,滿足條件給容器注冊bean
    2022-10-10
  • JAVA動態(tài)維度笛卡爾積輸出的實現(xiàn)

    JAVA動態(tài)維度笛卡爾積輸出的實現(xiàn)

    本文主要介紹了JAVA動態(tài)維度笛卡爾積輸出的實現(xiàn),通過動態(tài)生成笛卡爾積,可以方便地處理多維數(shù)據(jù)集,提高數(shù)據(jù)處理效率,具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • Java快速排序案例講解

    Java快速排序案例講解

    這篇文章主要介紹了Java快速排序案例講解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-08-08

最新評論

丘北县| 仙游县| 牡丹江市| 抚州市| 永泰县| 红安县| 息烽县| 西华县| 湛江市| 咸阳市| 新宁县| 高州市| 赤峰市| 北安市| 十堰市| 台前县| 平潭县| 星座| 奇台县| 本溪| 印江| 安龙县| 道真| 太湖县| 兴和县| 阿勒泰市| 酒泉市| 永仁县| 社旗县| 静宁县| 大冶市| 江川县| 青州市| 垣曲县| 定结县| 固安县| 潼南县| 信阳市| 仪陇县| 怀远县| 六盘水市|