当前位置:网站首页>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
边栏推荐
- Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
- MySQL数据库讲解(十)
- gzip和gunzip 解压参数详解
- Subscription number development of wechat applet (message push)
- 在Clion中给主函数传入外部参数
- leetcode--357. Count the number of different figures
- 某政务云项目业务系统迁移调研实践
- VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
- Multiple inheritance virtual base exercises
- VMware 15pro mounts the hard disk of the real computer in the deepin system
猜你喜欢

RobotFramework 之 文件上传和下载

Operation instructions of star boundary automatic text translator (advanced version)

Pycharm连接远程服务器并实现远程调试

01-NIO基础之ByteBuffer和FileChannel

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

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

OpenStack如何跨版本升级

Mock测试

Detailed tutorial on the use of smoke sensor (mq-2) (based on raspberry pie 3B +)

Storage path of mod subscribed by starbound Creative Workshop at Star boundary
随机推荐
JDBC详解
redis数据库讲解(三)redis数据类型
利用json-server在本地创建服务器请求
百度图片识别自定义实现(替代AipOcr)
返回数组排序后下标
云迁移的六大场景
RobotFramework 之 项目框架
VMware 15pro mounts the hard disk of the real computer in the deepin system
第四届“传智杯”全国大学生IT技能大赛(决赛B组) 题解
leetcode--977. Squares of a Sorted Array
MySQL数据库讲解(七)
Detailed tutorial on the use of setinterval timing function of wechat applet
星界边境文本自动翻译机(高级版)使用说明
Essential difference between restful WebService and gSOAP webservice
拨开云雾synchronized使用五种方式介绍
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
服务器日志分析工具(识别,提取,合并,统计异常信息)
Wechat applet obtains login user information, openid and access_ token
Multiple inheritance virtual base exercises
jsp学习1