欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

spring cloud學(xué)習(xí)教程之config修改配置詳解

 更新時(shí)間:2017年09月04日 10:12:39   作者:liaokailin  
這篇文章主要給大家介紹了關(guān)于spring cloud學(xué)習(xí)教程之config修改配置的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。

之前我們講過(guò)了spring cloud之config配置的相關(guān)內(nèi)容,那么在Git端修改配置后如何讓客戶(hù)端生效?下面來(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

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 (也可以通過(guò)本地下載

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論