spring-boot - Spring Cloud Config Server:如何覆盖应用程序特定文件中的共享属性
问题描述
我想按照下面的建议在多个应用程序中共享一些属性,并且我希望能够覆盖该值,因此如果我在 application-dev.properties 中有 x=1,我应该能够在我的应用程序特定文件中覆盖 x即在我的情况下 test_app-dev.properties 包含 x=2。所以当我打电话给http://local host:8888/test_app/dev x=1 胜过一切。文件在 git 中。它不应该返回 x=2 还是我误解了共享属性的意图?
在https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html中,“2.1.5 与所有应用程序共享配置”段落。它说:
使用基于文件的(即 git、svn 和本机)存储库,在 application* 中具有文件名的资源在所有客户端应用程序之间共享(如 application.properties、application.yml、application-*.properties 等)。您可以使用具有这些文件名的资源来配置全局默认值,并根据需要让它们被特定于应用程序的文件覆盖。
解决方案
最初我自己也面临这个问题。在查看了@user1549440 的答案后,对如何使用常用属性有了一个想法。将可共享配置文件夹安排为第一个可搜索路径后,它按预期工作。刚刚添加了方便解决方案的工作示例。
下面是中的示例配置configuration-server
。
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: file://app/configurations
default-label: master
search-paths:
- 'common*'
- 'petstore*'
- 'inventory*'
info:
app:
name: Configuration Server
description: Spring Cloud Configuration Server
version: 1.0.0
security:
user:
name: myname
password: mypass
以下是应用程序的示例文件夹结构。
├── app
│ └── configurations
│ ├── common
│ │ ├── application-dev.yml
│ │ ├── application-test.yml
│ │ ├── application-stg.yml
│ │ └── application-prod.yml
│ ├── inventory
│ │ ├── petstore-dev.yml
│ │ ├── petstore-test.yml
│ │ ├── petstore-stg.yml
│ │ └── petstore-prod.yml
│ └── petstore
│ ├── inventory-dev.yml
│ ├── inventory-test.yml
│ ├── inventory-stg.yml
│ └── inventory-prod.yml
推荐阅读
- django - 在 Django FormView(基于类的视图)中测试 contrib.messages
- typescript - 在 AWS CDK 中为 Api 网关指定处理程序时遇到问题
- google-chrome - 可以使用 chrome-remote-interface 检查来确定是否使用了摄像头和麦克风
- python - 为什么使用 format.join 函数时会出现错误
- python - 集群时出现内存错误
- r - 如何将几个空白 ggplots 添加到列表中?
- database - 如何显示2个仓库的产品总数?
- reactjs - 如何解决 TypeError: path.split is not a function
- flutter - 如何在flutter中处理error.response.data中的几个对象
- vue.js - 如何使用 Vue.js 在 Openlayers 包中添加“叠加层”