Spring Cloud配置客户端从同一repo检索多个属性文件。

问题描述 投票:0回答:1

我有一个检索属性文件的需求,并以环境名区分这些文件。

配置服务器正在监听这个repo (https:/github.comtpande1spring-cloud-config-repotreemaster。),其中有:config-client-dev.properties、config-client-sbx.properties、config-client-test.properties和config-client-prod.properties。

在客户端服务器上,我有下面的配置来读取上面的github repo。我如何在客户端应用程序中指定的环境下读取这些不同的属性?

示例性的休息代码。

@GetMapping("/message") //Pick message(SBX, DEV, Test, PROD) from the propertyfile from github
public String getMessage() {

    return message;

}

bootstrap.yml:

spring: profiles: dev application: name: config-client cloud: config: uri: http:/localhost:1000 /配置服务器端口配置文件:sbx、dev、test、prod。

management.endpoints.web.exposure.include: "*"

spring-boot spring-cloud spring-cloud-config
1个回答
0
投票

你可以在你的bootstrap yaml文件中添加多个活动配置文件。在你有spring.profile.active的选项中,在你的配置服务器中,你可以为每个profile添加搜索模式。

如以下链接中模式匹配部分所述。https:/cloud.spring.iospring-cloud-configmultimulti__spring_cloud_config_server.html。

© www.soinside.com 2019 - 2024. All rights reserved.