当前位置:网站首页>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
边栏推荐
- Jira截取全图
- Easyexcel读取excel表地理位置数据,按中文拼音排序
- Recyclerview advanced use (I) - simple implementation of sideslip deletion
- On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
- On September 8, the night before going to Songshan Lake
- RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
- 线程组ThreadGroup使用介绍+自定义线程工厂类实现ThreadFactory接口
- 第四届“传智杯”全国大学生IT技能大赛(决赛B组) 题解
- 某政务云项目业务系统迁移调研实践
- Jmeter安装教程以及我遇到的问题的解决办法
猜你喜欢
MYSQL一种分表实现方案及InnoDB、MyISAM、MRG_MYISAM等各种引擎应用场景介绍
困扰多年的系统调研问题有自动化采集工具了,还是开源免费的
Call wechat customer service applet
Recyclerview advanced use (I) - simple implementation of sideslip deletion
Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
正则表达式
星界边境Starbound创意工坊订阅的mod的存放路径
政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
MySQL数据库讲解(十)
RobotFramework 之 文件上传和下载
随机推荐
logback-logger和root
About the configuration and use of json5 in nodejs
Call wechat customer service applet
关于云容灾,你需要知道这些
Chrome插件 之 Selenium IDE、XPath 安装
HyperMotion云迁移助力中国联通,青云完成某央企上云项目,加速该集团核心业务系统上云进程
VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
线程组ThreadGroup使用介绍+自定义线程工厂类实现ThreadFactory接口
Essential difference between restful WebService and gSOAP webservice
Multiple inheritance virtual base exercises
第四届“传智杯”全国大学生IT技能大赛(决赛B组) 题解
postman批量生产body信息(实现批量修改数据)
使用开源调研工具Prophet是一种什么体验?
在MAC上安装mysql
ActiveMQ Basics
pthread_ Why does self() repeat
帆软调用动态传参的方法,在标题中设置参数
jsp学习1
获取线程返回值Future接口与FutureTask类使用介绍
Logback logger and root