<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Config簡介 隨著微服務數量不斷增加,需要系統具有可伸縮性和可擴展性,能夠管理相當的的服務實例的配置管理,系統需要建立一個統一的配置管理中心。Spring Cloud 提供了分布式配置中心Spring Cloud Config,服務端默認的存儲實現是Git,支持配置環境的標簽版本。配置服務還支持多種倉庫實現,如文件系統、Svn等。 本系統配置中心包含3個部分,配置服務器、客戶端、Git倉庫。 ## 1、客戶端 配置依賴,引入starter ``` <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> ``` 啟動配置類文件bootstrap.yml ``` eureka: client: service-url: defaultZone: http://127.0.0.1:8092/eureka spring: cloud: config: discovery: service-id: CITP-CONFIG-SERVER # 指定配置中心服務端的server-id enabled: true #是否開啟 label: master #指定倉庫分支 profile: dev #指定版本 username: xxx password: xxx ``` 2.配置倉庫 在建立配置服務器之前,需要現在git建立一個配置倉庫,配置倉庫如圖: ![](https://img.kancloud.cn/a2/f5/a2f5ec772433dfbf058b5c7d02cdd1e0_986x459.png) 3.配置服務端 添加以下依賴: ``` <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> <!-- 安全保護 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> ``` 在入口application加入@EnableConfigServer、@EnableEurekaClient注解。 啟動類配置文件bootstrap.yml配置Git信息: ``` spring: application: name: citp-config-server cloud: config: server: git: uri: http://36.112.138.44:8081/CITPGroup/citp/config-demo.git #git配置地址 username: #git賬號 password: #git密碼 default-label: master #分支信息 search-paths: config #配置文件所在根目錄 ``` 4.客戶端驗證 新建配置類讀取git配置信息 ``` @Component @ConfigurationProperties(prefix = "user") public class UserConfig { private String username; private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } ``` 新建controller驗證讀取信息 ``` @RestController public class ConfigController { @Autowired private UserConfig userConfig; @GetMapping("/getValue") public String getConfig(){ return userConfig.getUsername(); } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看