java B2B2C Springcloud電子商務平臺源碼- config 修改配置

在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電子商務平臺源碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章