spring cloud學(xué)習(xí)教程之config修改配置詳解
之前我們講過了spring cloud之config配置的相關(guān)內(nèi)容,那么在Git端修改配置后如何讓客戶端生效?下面來一起看看詳細的介紹吧。
訪問接口修改
refresh
post方式執(zhí)行http://localhost/refresh 會刷新env中的配置
restart
如果配置信息已經(jīng)注入到bean中,由于bean是單例的,不會去加載修改后的配置
需要通過post方式去執(zhí)行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); } }
在執(zhí)行refresh時會刷新bean中變量值。
ok ~ it's work ! more about is here (也可以通過本地下載)
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
SpringBoot整合MP通過Redis實現(xiàn)二級緩存方式
這篇文章主要介紹了SpringBoot整合MP通過Redis實現(xiàn)二級緩存方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01springmvc+mybatis 做分頁sql 語句實例代碼
本文通過一段實例代碼給大家介紹了springmvc+mybatis 做分頁sql 語句的方法,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友參考下吧2017-07-07Mybatis-Plus中IdType.AUTO局部配置不生效的問題解決
本文主要介紹了Mybatis-Plus中IdType.AUTO局部配置不生效的問題解決,數(shù)據(jù)庫插入數(shù)據(jù)時,id的默認生成方式還是雪花算法,局部配置沒有生效,下面就來解決一下,感興趣的可以了解一下2023-09-09Java動態(tài)代理的兩種實現(xiàn)方式詳解【附相關(guān)jar文件下載】
這篇文章主要介紹了Java動態(tài)代理的兩種實現(xiàn)方式,結(jié)合實例形式分析了java動態(tài)代理的相關(guān)原理、實現(xiàn)方法與操作技巧,并附帶相關(guān)jar文件供讀者下載,需要的朋友可以參考下2019-03-03Linux將Spring Boot項目的Jar包注冊為開機自啟動系統(tǒng)服務(wù)的操作方法
jar文件是從maven package打包出來的,config/application.yml是原先在項目的resources文件夾里,外置出來方便適配開發(fā)環(huán)境和正式環(huán)境,這篇文章主要介紹了Linux將Spring Boot項目的Jar包注冊為開機自啟動系統(tǒng)服務(wù)的操作方法,需要的朋友可以參考下2023-10-10為什么mybatis中的SqlSession一定要關(guān)閉
這篇文章主要介紹了為什么mybatis中的SqlSession一定要關(guān)閉,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12