电竞比分网-中国电竞赛事及体育赛事平台

分享

springcloud(第二篇)springcloud config 修改配置

 WindySky 2017-07-17


Git端修改配置后如何讓客戶端生效?

訪問接口修改

  • refresh
    post方式執(zhí)行http://localhost/refresh 會刷新env中的配置
  • restart
    如果配置信息已經(jīng)注入到bean中,由于bean是單例的,不會去加載修改后的配置
    需要通過post方式去執(zhí)行http://localhost/restart,
    需要通過application.properties中配置endpoints.restart.enabled=true啟動指定的端口

弊端: 通過restart耗時比較長,因此就有了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);
    }
}

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多