Spring 云配置 - 访问所有微服务中的共享属性文件

Spring Cloud Configuration - Access shared properties file in all microservices

在我的 spring 云配置服务器 application.properties 中。我在我的应用程序中通过了@EnableConfigServer class

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 仓库中 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 存储库中存在的 属性,但出现错误 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>