<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ![](https://img.kancloud.cn/3a/98/3a98395d1e5c139c986ef08045fa6498_993x336.jpg) 當我修改存儲在 Gitee 上的配置時,Config Server 不需要重啟即可同步 Gitee 上的配置,但是 Config Client 需要重啟才能進行同步。如果每次修改都要重啟,那么將是一個噩夢。 <br/> 而下面將要學習的動態刷新就可以解決這個問題,當更改存儲在 Gitee 上的配置時,客戶端不再需要重啟即可同步配置。 <br/> 步驟如下: **1. 在 cloud-config-client-3355 客戶端的`pom.xml`中添加 `actuator` 依賴** ```xml <dependencies> <!-- config --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!-- actuator --> <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.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> ... </dependencies> ``` **2. 在 cloud-config-client-3355 客戶端的`bootstrap.yml`中暴露監控端口** ```yml #暴露監控端點 management: endpoints: web: exposure: include: "*" ``` **3. 在 cloud-config-client-3355 客戶端的`ConfigController`上添加注解`@RefreshScope`** ```java @RestController @RefreshScope public class ConfigController { @Value("${app.version:default}") private String version; @Value("${app.name:default}") private String name; @GetMapping("/config") public String getConfigInfo() { return "app.name:" + name + ",version:" + version; } } ``` **4. 啟動 3344 服務端和 3355 客戶端** 在沒有更新Gitee上的 `cloud-config-client-3355-test.yml` 配置文件前,訪問 http://localhost:3355/config ,獲取如下內容。 ``` app.name:cloud-config-client-3355,version:test-1.0 ``` **5. 到 Gitee 上修改 `cloud-config-client-3355-test.yml` 文件** 修改內容如下: ``` app: name: cloud-config-client-3355 version: test-2.0 #之前是 test-1.0 ``` 沒有重啟 cloud-config-client-3355 前提下,刷新 http://localhost:3355/config ,依舊是 `test-1.0`,說明 3355 客戶端沒有同步 Gitee 上的配置。 ``` app.name:cloud-config-client-3355,version:test-1.0 ``` **6. 運行下面的命令刷新 cloud-config-client-3355 客戶端** ```shell curl -X POST http://localhost:3355/actuator/refresh ``` ![](https://img.kancloud.cn/e2/6b/e26b302478700f3afacf52a4ac6e168a_1218x184.jpg) 在沒有重啟 cloud-config-client-3355 客戶端的前提下,刷新 http://localhost:3355/config ,可以看到由原來的 `test-1.0` 更新為 `test-2.0`,說明 3355 客戶端已經與 Gitee 上的配置同步成功! ``` app.name:cloud-config-client-3355,version:test-2.0 ``` <br/> 但是上面講的這種同步方式做不到這兩點需求:廣播通知和定點通知。 * 廣播通知:即只需要通知其中某一個 config client 客戶端,其它 config-client 也能知道配置更新了,這樣就不用發送那么多次的`curl -X POST ...`請求。 * 定點通知:即我想更新哪個 config client 的配置我就更新哪一個的,不想更新的就不更新。 而且這種方式需要運維人員手動發送`curl -X POST ...`請求,本質上還是手動刷新,不是自動刷新,要解決這些問題,需要引入 Spring Cloud Bus 消息總線。
                  <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>

                              哎呀哎呀视频在线观看