java - Spring could config server 目录组织与 searchPaths 不起作用
问题描述
我工作的公司决定将 SpringBoot 项目的所有配置属性集中在一个地方。为此,我们配置了spring-cloud-config-server
指向 Github 存储库的指向。
在 github 上,我们为我们拥有的每个应用程序创建了一个文件夹。例子:
-https://github.com/myusername/my-spring-cloud-config-repo (Github's base folder)
--my-project-1 (folder)
---my-project-1.properties (file)
---application-dev.properties (file)
---application-prod.properties (file)
--my-project-2 (folder)
---my-project-2.properties (file)
---application-dev.properties (file)
---application-prod.properties (file)
---application-test.properties (file)
最初,application.properties
我们spring-cloud-config-server
有以下配置:
server.port=9090
spring.cloud.config.server.git.uri=https://github.com/myusername/my-spring-cloud-config-repo.git
spring.cloud.config.server.git.username=myusername
spring.cloud.config.server.git.password=mypassword
spring.cloud.config.server.git.skip-ssl-validation=true
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.force-pull=true
spring.cloud.config.server.git.searchPaths=*/**
因此,一旦我们启动服务器,我们就可以发送 HTTP 请求:
http://localhost:9090/my-project-2/test
它会成功返回文件夹内外的所有配置my-project-2.properties
,这是所需的行为。
当我们发送时,问题就开始了:application-test.properties
my-project-2
http://localhost:9090/my-project-2/dev
因为它会返回文件夹内外的所有配置my-project-2.properties
,也会返回文件夹中的文件。发生这种情况是因为强制配置服务器在存储库的所有文件夹上搜索“dev”文件,并且每次客户端启动时最终都会导致冲突。application-dev.properties
my-project-2
application-dev.properties
my-project-1
searchPaths=*/**
为了解决这个问题,根据Here和Here,我可以wildcards
在searchPaths
配置中使用:
spring.cloud.config.server.git.searchPaths={application}/{profile}
但它没有用......我也尝试了很多组合:
searchPaths={application}/{profile}.properties
searchPaths={application}/**
searchPaths=/{application}/{profile}
searchPaths='{application}/{profile}'
searchPaths='{application}/{profile}.properties'
searchPaths='{application}'/'{profile}'
(我根据spring cloud config searchPaths的答案尝试了单引号的想法)
但他们都没有为我工作。我应该如何配置该searchPaths
属性以使其用于我的目的?提前致谢。
解决方案
推荐阅读
- oracle - 在 oracle 查询中使用带有更新的案例
- c# - 从 sqlite 数据库性能初始化 c# 对象的最佳实践是什么
- jasper-reports - 如何将参数传递给 IReport 中的数据集?
- angular - JHipster - 用新的角度模板替换默认模板
- reactjs - React - 表单中的依赖字段
- javascript - 通过使用在每个子数组的第一个元素中找到的子字符串作为键来组合子数组
- ios - UITableView contentSize 太大了 10pt(仅限 iOS 10!)
- r - 在 ggplot 的 axis.text.x 名称中添加多种颜色
- docker - 使用 Docker 正确设置 Indy
- polly - POLLY Nuget 包 WaitAndRetryAsync 方法