我使用Spring Boot开发了一个微服务 . 此服务使用Spring Cloud 配置服务器获取属性 . 这个微服务接受头文件中的版本,并根据版本,它执行适当的功能 . 在我的github repo中,我有2个分支,每个版本1个 . 该服务通常将以下信息发送到配置服务器以获取属性 -
应用程序名称配置文件标签
有没有办法在我的.yml文件中使用占位符代替标签?我希望标签动态设置为v1,如果我在 Headers v2中看到v1 .
EDIT:
我在本文档(http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html)的"Placeholders in Git URI"部分看到对占位符的引用,但我不确定如何从传入的请求中动态替换值
1 回答
spring-cloud-config-server提供了几个REST API,允许直接查询属性文件:
您可以动态使用您选择的任何标签,只要它与git上的现有标签匹配即可 .
例如,要检索
application.properties
,在git中标记为v1
:Config-server REST API:
///{label:.*
//-.properties
/-.json
//-.json
//-.yml
//-.yaml
/-.yml
/-.yaml
//{profiles: . [^-] . }
/-.properties
/ / / / **
我在git上尝试了一个带有属性文件的示例
spring-cloud-server
项目 . 我在文件中为每个标签应用了不同值的git标签v1
和v2
(我使用了配置文件remote
):label v1 :
label v2 :
no label :
Java code
我没有尝试过,但我想你也可以使用cloud-config-server的java API(直接注入和调用控制器而不是执行http请求):