簡體   English   中英

Spring Cloud Config Server無法解析占位符

[英]Spring Cloud Config Server Could not resolve placeholder

我將spring-cloud-config-server添加到我的堆棧中,希望為不同的spring配置文件(即開發,暫存和生產)加載不同的配置集。

我的配置服務器應用程序從端口8888開始,直接從私有gitlab存儲庫中獲取配置,並且具有安全性。 我通過手動點擊並檢查是否返回了正確的屬性來進行測試。 到現在為止還挺好。

我將有幾個“客戶端”應用程序,我想使用配置服務器中的屬性,但現在我只嘗試其中一個。 為了測試,我已經放了一個

@Value("${some.property}")
private string someProperty;

在客戶端應用程序中的我的網絡資源之一中。 此屬性不在客戶端應用程序的任何屬性文件中(這可能是個問題,這很奇怪-但如果存在問題,則似乎是限制性的)。

我也已將客戶端應用程序指向配置服務器。 配置服務器和客戶端應用程序的配置都位於其bootstrap.properties文件中,以確保它們在此過程的早期加載。

實際上,我的兩個應用程序都在Docker映像中進行了容器化,並由docker-compose.yml文件啟動。 我實際上已經將其設置為客戶端應用程序在啟動之前等待配置服務器運行。

在客戶端應用程序啟動期間,我可以看到它從配置服務器獲取配置:

| 20:12:50.692 [main] INFO  o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment 205 - Fetching config from server at : http://config-server:8888

205似乎很成功。

但是,客戶端應用程序啟動失敗:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exampleResource': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'some.property' in value "${some.property}"

我在客戶端應用程序中將活動配置文件設置為“開發”。 配置服務器上的屬性文件名為:

myapp-development.properties
myapp-staging.properties
myapp-production.properties

我當然希望客戶端應用程序從服務器獲取配置(我可以看到這種情況),然后該屬性在啟動時可供客戶端應用程序使用,但事實並非如此。 它像在值注釋中指定默認值一樣簡單嗎? 還是我忽略了更基本的東西? 我按照本指南的說明進行操作,並且我的配置服務器指向上面提到的git存儲庫:

http://www.baeldung.com/spring-cloud-configuration

提前致謝。

您在客戶端應用程序中錯誤地設置了憑據。

它應該是

spring.cloud.config.username=myConfigServerUserName
spring.cloud.config.password=myConfigServerPassword

而不是spring.security.user.namespring.security.user.password (在配置服務器應用程序中使用)。

參見: http : //cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.1.RELEASE/single/spring-cloud-config.html#_security_2

暫無
暫無

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

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