在git端修改配置後如何讓用戶端生效?
需要JAVA Spring Cloud大型企業分布式微服務雲建構的B2B2C電子商務平台源碼 一零三八七七四六二六
通路接口修改
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中變量值。
java B2B2C Springcloud電子商務平台源碼