【问题标题】:Spring Cloud Configuration - Access shared properties file in all microservicesSpring Cloud Configuration - 访问所有微服务中的共享属性文件
【发布时间】:2020-11-21 12:48:24
【问题描述】:

在我的 spring 云配置服务器 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}"

【问题讨论】:

    标签: java spring spring-boot spring-mvc microservices


    【解决方案1】:

    解决方案

    bootstrap.properties 默认不启用。请在您的微服务中添加此依赖项。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-01
      • 2018-03-31
      • 2015-05-14
      • 2015-01-23
      • 1970-01-01
      • 2017-12-14
      • 2016-02-19
      • 2017-05-27
      相关资源
      最近更新 更多