之前我們講過(guò)了spring cloud之config配置的相關(guān)內(nèi)容,那么在Git端修改配置后如何讓客戶端生效?下面來(lái)一起看看詳細(xì)的介紹吧。
訪問(wèn)接口修改
refresh
post方式執(zhí)行http://localhost/refresh 會(huì)刷新env中的配置
restart
如果配置信息已經(jīng)注入到bean中,由于bean是單例的,不會(huì)去加載修改后的配置
需要通過(guò)post方式去執(zhí)行http://localhost/restart,
需要通過(guò)application.properties
中配置endpoints.restart.enabled=true
啟動(dòng)指定的端口
弊端: 通過(guò)restart耗時(shí)比較長(zhǎng),因此就有了RefreshScope
RefreshScope
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package com.lkl.springcloud.config.client; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Created by liaokailin on 16/4/28. */ @EnableAutoConfiguration @ComponentScan @RestController @RefreshScope public class Application { @Value ( "${name:World!}" ) String name ; @RequestMapping ( "/" ) public String home(){ return "Hello " + name; } public static void main(String[] args) { SpringApplication.run(Application. class ,args); } } |
在執(zhí)行refresh時(shí)會(huì)刷新bean中變量值。
ok ~ it's work ! more about is here
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)服務(wù)器之家的支持。
原文鏈接:http://blog.csdn.net/liaokailin/article/details/51307603