[英]Spring Cloud Config: client doesn't attempt to connect to the config server
我正在嘗試創建一個簡單的 Spring Cloud Config 服務器/客戶端設置,並且大致遵循文檔:
https://cloud.spring.io/spring-cloud-config/reference/html/
到目前為止,我已經實現了一個似乎可以正常工作的服務器,即當我調用相應的端點時返回正確的屬性值:
GET http://localhost:8888/config-client/development
{
"name": "config-client",
"profiles": [
"development"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "classpath:/config/config-client-development.properties",
"source": {
"user.role": "Developer"
}
}
]
}
但是,我沒有讓客戶端連接到服務器的運氣。 我做了以下事情:
spring-cloud-starter-config
依賴:<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
bootstrap.properties
文件:spring.application.name=config-client
spring.profiles.active=development
spring.cloud.config.uri=http://localhost:8888
但我還是得到了
java.lang.IllegalArgumentException: Could not resolve placeholder 'user.role' in value "${user.role}"
嘗試運行客戶端應用程序時。
應用程序日志中沒有任何內容看起來像是客戶端正在嘗試與配置服務器通信。
鏈接到重現問題的最小GitHub 存儲庫: https://github.com/Bragolgirith/spring-cloud-minimal
重現步驟:
config-service
應用程序config-client
應用程序知道我做錯了什么嗎?
OK,謎底解開了。
似乎一周前發布了一個新的 Spring Cloud 版本( https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available )有一種激活引導過程的新方法 - 現在默認情況下不會發生,但需要添加額外的依賴項:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
雖然這個新版本現在是您使用 Spring Initializr 時獲得的默認版本,但文檔仍未更新以反映更改 - 它們僅在發行說明中簡要提及。
作為使用上述spring-cloud-starter-bootstrap
依賴項和bootstrap.properties
文件的替代方案,現在似乎以下內容也是可能的(甚至是首選):
應用程序.properties
spring.application.name=config-client
spring.profiles.active=development
spring.config.import=configserver:http://localhost:8888
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.