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

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

在git端修改配置后如何让客户端生效?

访问接口修改

  • refresh
    post方式执行http://localhost/refresh 会刷新env中的配置
  • restart
    如果配置信息已经注入到bean中,由于bean是单例的,不会去加载修改后的配置
    需要通过post方式去执行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);
    }
}

在执行refresh时会刷新bean中变量值。

ok ~ it’s work ! more about is here
转载请注明
http://blog.csdn.net/liaokailin/article/details/51307603

欢迎关注,您的肯定是对我最大的支持

这里写图片描述

猜你喜欢

转载自blog.csdn.net/liaokailin/article/details/51307603