構建SpringCloud配置服務器的步驟

這篇文章主要介紹“構建Spring Cloud配置服務器的步驟”,在日常操作中,相信很多人在構建Spring Cloud配置服務器的步驟問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”構建Spring Cloud配置服務器的步驟”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

創(chuàng)新互聯(lián)建站主營峽江網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,手機APP定制開發(fā),峽江h(huán)5重慶小程序開發(fā)搭建,峽江網(wǎng)站營銷推廣歡迎峽江等地區(qū)企業(yè)咨詢

實現(xiàn)步驟:

1. 在Configuration Class標記@EnableConfigServer

2. 配置文件目錄(基于git)

cloud.properties(默認) //默認環(huán)境,跟隨代碼倉庫

cloud-dev.properties(proflie="dev")//開發(fā)環(huán)境

cloud-test.properties(proflie="test")//測試環(huán)境

cloud-staging.properties(proflie="staging")//預發(fā)布環(huán)境

cloud-prod.properties(proflie="prod")//生產(chǎn)環(huán)境

3. 服務端配置版本倉庫

spring.cloud.config.server.git.uri=https://github.com/****test****/springcloud.git

spring.cloud.config.server.git.searchPaths=properties

spring.cloud.config.label=master

spring.cloud.config.server.git.username=

spring.cloud.config.server.git.password=

完整配置項:

spring.application.name = config-server

server.port=9090

management.endpoints.web.exposure.include=*

management.endpoint.health.show-details=always

spring.cloud.config.server.git.uri=https://github.com/****test****/springcloud.git

spring.cloud.config.server.git.searchPaths=properties

spring.cloud.config.label=master

spring.cloud.config.server.git.username=

spring.cloud.config.server.git.password=

構建Spring Cloud配置客戶端

實現(xiàn)步驟:

1. 創(chuàng)建 bootstrap.properties 或者 bootstrap.yml 文件

2. bootstrap.properties 或者 bootstrap.yml 文件中配置客戶端信息(以下是bootstrap.properties )

##配置服務器URI

spring.cloud.config.uri = http://localhost:9090/

##配置客戶端應用名稱

spring.cloud.config.name = cloud

##激活配置

spring.cloud.config.profile = prod

##在github上的分支名

spring.cloud.config.label = master

3. 設置敏感性安全

management.endpoints.web.exposure.include=*

4. 設置健康檢查

management.endpoint.health.show-details=always

@RefreshScope用法

@RestController

@RefreshScope

public class EchoController {

@Value("${my.name}")

private String myName;

@GetMapping("/my-name")

public String getName() {

return myName;

}

}

用戶調(diào)用/actuator/refresh控制客戶端配置更新

實現(xiàn)定時更新客戶端

@SpringBootApplication

@EnableScheduling

public class SpringCloudConfigServerClientApplication {

private final ContextRefresher contextRefresher;

private final Environment environment;

@Autowired

public SpringCloudConfigServerClientApplication(ContextRefresher contextRefresher,

Environment environment) {

this.contextRefresher = contextRefresher;

this.environment = environment;

}無錫人流醫(yī)院 http://www.wxbhffk.com/

public static void main(String[] args) {

SpringApplication.run(SpringCloudConfigServerClientApplication.class, args);

}

@Scheduled(fixedRate = 5*1000, initialDelay = 3*1000)

public void autoRefresh() {

Set updatePropertyNames = contextRefresher.refresh();

updatePropertyNames.forEach(name -> System.err.println(">>>>>>"+name+environment.getProperty(name)));

if(!updatePropertyNames.isEmpty()) {

System.err.printf("[Thread :%s] 當前配置已更新,具體項目:%s \n",

Thread.currentThread().getName(),

updatePropertyNames);

}

}

}

健康檢查

意義

比如應用可以任意地輸出業(yè)務健康、系統(tǒng)健康等指標

端點URI:/actuator/health

實現(xiàn)類:HealthEndpoint

健康指示器:HealthIndicator,

HealthEndpoint:HealthIndicator,一對多

自定義實現(xiàn)HealthIndicator

1. 實現(xiàn)AbstractHealthIndicator

public class MyHealthIndicator extends AbstracHealthIndicator{

@Override

protected void doHealthCheck(Health.Builder builder) throws Exception{

builder.up().withDetail("MyHealthIndicator",">>Up>>");

}

}

2. 暴露MyHealthIndicator為bean

@Bean

public MyHealthIndicator myHealthIndicator(){

return new MyHealthIndicator();

}

3. 依賴

org.springframework.hateoas

spring-hateoas

到此,關于“構建Spring Cloud配置服務器的步驟”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

本文題目:構建SpringCloud配置服務器的步驟
網(wǎng)站路徑:http://muchs.cn/article38/ippdsp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、商城網(wǎng)站、軟件開發(fā)、網(wǎng)站內(nèi)鏈網(wǎng)站收錄、動態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設