当前位置:网站首页>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
边栏推荐
- 多云数据流转?云上容灾?年前最后的价值内容分享
- 帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
- 帆软中根据分类进行汇总
- leetcode--977. Squares of a Sorted Array
- 政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
- 帆软之单元格部分字体变颜色
- About the configuration and use of json5 in nodejs
- Wechat applet input hidden and inoperable settings
- 报表FCRA考试题集及答案(错了11题)
- Jacob print word
猜你喜欢

win10自带Groove音乐不能播放CUE和APE文件的一种曲线救国办法,自己创建aimppack插件包,AIMP安装DSP插件

Promtail + Loki + Grafana 日志监控系统搭建

关于云容灾,你需要知道这些

RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复

修改ddt生成的测试用例名称

帆软之单元格部分字体变颜色

星界边境Starbound创意工坊订阅的mod的存放路径

HyperMotion云迁移助力中国联通,青云完成某央企上云项目,加速该集团核心业务系统上云进程

Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)

Logback logger and root
随机推荐
findstr不是内部或外部命令解决方法
std::map 和 std::vector 内存释放
mysql 5.1升级到5.611
RobotFramework 之 文件上传和下载
ActiveMQ Basics
RobotFramework 之 项目框架
mysql 5.1升级到5.67
报表FCRA考试题集及答案(错了11题)
Algorithem_ReverseLinkedList
关于Jmeter启动闪退问题
修改ddt生成的测试用例名称
Subscription number development of wechat applet (message push)
政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
倒计时1天~2022云容灾产品线上发布会即将开始
Operation instructions of star boundary text automatic translator
Wechat applet positioning and ranging through low-power Bluetooth device (2)
线程间控制之CountDownLatch和CyclicBarrier使用介绍
Promtail + Loki + Grafana 日志监控系统搭建
Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)