簡體   English   中英

Spring Cloud 配置 - 訪問所有微服務中的共享屬性文件

[英]Spring Cloud Configuration - Access shared properties file in all microservices

在我的 Spring Cloud 配置服務器 application.properties 中。 我在我的應用程序類中通過了 @EnableConfigServer

spring.application.name=CONFIG_SERVER
server.port=1080
spring.cloud.config.server.git.uri=PATH_TO_GITHUB_REPO
spring.cloud.config.server.git.username=USNM
spring.cloud.config.server.git.password=PWD
spring.cloud.config.server.git.skip-ssl-validation=true

在我的 git repo application.properties 里面

third-party-cred=MY_VALUE

在我的 spring 雲配置客戶端 bootstrap.properties

server.port=1081
spring.application.name=MY_SERVICE
spring.cloud.config.uri=http://localhost:1080

我正在嘗試在我的微服務中使用@Value訪問 git repo 中存在的屬性,但它給出了錯誤Could not resolve placeholder 'third-party-cred' in value "${third-party-cred}" @Value Could not resolve placeholder 'third-party-cred' in value "${third-party-cred}"

解決方案

bootstrap.properties 默認不啟用。 請在您的微服務中添加此依賴項。

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

暫無
暫無

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

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