当前位置:网站首页>yml引用其他变量
yml引用其他变量
2022-04-23 14:08:00 【阿闰】
参考:YAML文件(.yml)中的键(key)通过变量引用来设置 - i江湖中人 - 博客园
通过变量引用设置配置量的【值(value)】
在YAML文件中,一个配置量的值可以通过引用另一个变量来设置。例如:
default-db:
port: 3306
user-db:
port: ${default-db.port}
但是,如果想通过变量引用设置键,通过${}是做不到的。例如:
site:
url:
user: www.user.net
shop: www.shop.net
site:
slogan:
${site.url.user}: everyone is great!
${user.url.shop}: buy anything you want!
在将配置读入程序中之后,你会发现上述的${}引用,并没有替换成真正的值。
通过锚点引用设置配置量的【键(key)】
要想替换键,则需要用到锚点。锚点用符号“&”定义,并用符号“*”进行引用。
锚点有两种使用方式,一是通过“<<:”将键值对一起引入:
default-db: &default-db-config
host: 127.0.0.1
port: 3306
user-db:
<<: *default-db-config
其实际效果如:
default-db:
host: 127.0.0.1
port: 3306
user-db:
host: 127.0.0.1
port: 3306
说明:&后面的锚点名字,可自己定义,不必与配置量的键相同。
另一种是仅引入配置的值:
site:
url:
user: &site.user www.user.net
shop: &site.shop www.shop.net
site:
slogan:
*site.user: everyone is great!
*site.shop: buy anything you want!
其实际效果如:
site:
url:
user: www.user.net
shop: www.shop.net
site:
slogan:
www.user.net: everyone is great!
www.shop.net: buy anything you want!
说明:用&定义锚点时,注意锚点名前后的空格。
另一个仅引入值例子:
color:
- &red-color red
- yellow
- blue
- *red-color
- gray
其实际效果如:
color:
- red
- yellow
- blue
- red
- gray
参考文档:
版权声明
本文为[阿闰]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wasd986523/article/details/120249547
边栏推荐
- 预览CSV文件
- sql中出现一个变态问题
- leetcode--380. O (1) time insertion, deletion and acquisition of random elements
- Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动
- Switch usage (wechat applet)
- RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
- 关于训练过程中损失函数出现断崖式增长的问题
- 某政务云项目业务系统迁移调研实践
- 政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
- 快速搞懂线程实现的三种方式
猜你喜欢
随机推荐
jsp学习1
postman批量生产body信息(实现批量修改数据)
服务器日志分析工具(识别,提取,合并,统计异常信息)
星界边境文本自动翻译机(高级版)使用说明
政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
Understand the concepts of virtual base class, virtual function and pure virtual function (turn)
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
Mock测试
mysql 5.1升级到5.610
拨开云雾synchronized使用五种方式介绍
POI operation word template replaces data and exports word
gzip和gunzip 解压参数详解
DDT+Excel进行接口测试
Wechat applet communicates with low-power Bluetooth - sending data to hardware (III)
不同时间类型的执行计划计算
OpenStack命令操作
VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
Pycharm连接远程服务器并实现远程调试
Subscription number development of wechat applet (message push)
倒计时1天~2022云容灾产品线上发布会即将开始









