在Git端修改配置后如何讓客戶(hù)端生效?
訪(fǎng)問(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);
}
}
|