A Problem about Spring Cloud Config Auto-refresh

問題

在學習Spring cloud config模塊時,通常都是跟着官網的Centralized Configuration | quick-start作一遍.html

但在下面這步的時候,出現問題了:git

configuration-client/src/main/resources/bootstrap.properties

spring.application.name=a-bootiful-client
# N.B. this is the default:
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=false
複製代碼

最後一句出現了紅線,也就是這個無效了。web

若是你無視這個問題,繼續往下作:spring

大體翻譯下: 改變git倉庫中的a-bootiful-client.properties文件中的message值(好比改成Hello Spring),記得commit一下,你能夠經過訪問 http://localhost:8888/a-bootiful-client/default來驗證config服務器已經知道了改變,你須要調用 refresh方法來強制客戶端去獲取新的值.......你能夠經過使用 post方法去請求 http://localhost:8888/refresh來調用 refresh方法,而後訪問 http://localhost:8080/message來驗證是否生效。

然而當你使用post方法去請求http://localhost:8888/refresh時,返回的404。bootstrap

緣由

docs.spring.io | 50.2 Exposing Endpoints這個文檔講到了:bash

因爲endpoints中會包含不少敏感信息,你須要當心的暴露它們,下面這張表展現了默認暴露的接口。這也是 management.security.enabled=false被刪除的緣由

這裏就不貼表的截圖了,能夠點擊上面的鏈接詳細查看,會發現除了health和info兩個支持web訪問外,其餘的默認不支持web訪問。服務器

解決方法

在bootstrap.properties文件中添加下面的代碼 management.endpoints.web.exposure.include=*app

暴露所有endpoints,你也能夠指定須要暴露的endpoints。ide

相關文章
相關標籤/搜索