簡體   English   中英

Spring 雲配置客戶端執行器刷新

[英]Spring Cloud Config Client Actuator Refresh

我有一個監聽配置服務器的客戶端。 Config Server 指向 github。 本地主機工作正常。 但是,當我將應用程序部署到 Kubernetes 時,刷新屬性的客戶端端點無法正常工作。

端點(發布): http://config-client.sbx.com/actuator/refresh

這將在 Postman "[]" 上返回一個空響應,並且響應代碼為 200 OK。 我可以看到配置服務器已在 K8s 上啟動並運行。

關於什么可能是錯的任何建議?

PS 我啟用了調試日志,但在那里看不到太多信息。

您能否在刷新時驗證應用程序鏈接是否已獲取主機名和應用程序名稱。 因為在 localhost 中進行刷新時,它只是本地的 springboot 應用程序,因此不需要額外的 application-name 路徑。 當您通常部署到服務器時,除了主機名之外,我們還必須提供應用程序的路徑名。 在tomcat中,我使用的URL如下,

http://<hostname>/**<application-name>**/actuator/refresh/

通常,當您通過 postman 訪問此 URL 時,它會給您一個 200 響應,其中的 [] 為空。 然后,您應該能夠在客戶端應用程序的日志文件中看到以下行。 [我還在應用程序的 main 方法中在 @SpringBootApplication 屬性下方設置了屬性@RefreshScope屬性來刷新應用程序的屬性。]

INFO   o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment:249 - Fetching config from server at : http://<hostname>/<Config-server-application-name>/
INFO   o.s.c.c.c.ConfigServicePropertySourceLocator.log:168 - Located environment: name=config-client, profiles=[development], label=null, version=ab36989c85922f1c9cf7803fac4, state=null
INFO   o.s.c.b.c.PropertySourceBootstrapConfiguration.initialize:112 - Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://<gitlaburl>/<companyname>/config-server.git/config-client-development.yml'}]
INFO   o.s.boot.SpringApplication.logStartupProfileInfo:655 - The following profiles are active: development
INFO   o.s.boot.SpringApplication.logStarted:61 - Started application in 1.557 seconds (JVM running for 70689.032)

對於 Kubernetes,

嘗試使用

kubectl 應用

(而不是 kubectl 創建配置映射。)

要部署配置 map,只需在 Kubernetes 上運行以下命令:

kubectl apply -f config-map.yml

確保配置 map 的名稱與 spring 啟動應用程序的名稱匹配。另請參見以下鏈接,

https://github.com/spring-cloud/spring-cloud-kubernetes/issues/255

還有一個 spring 雲 kuberenetes,您可以如下探索,

https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/2.0.0.M1/reference/html/#why-do-you-need-spring-cloud-kubernetes

我的客戶端中有application.propertiesbootstrap.properties文件。 在這種情況下,您應該在 bootstrap.yml 中指定spring.application.namespring.cloud.config.server.git.uri 我沒有刷新applicaiton.properties內具有spring.application.name的屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM