SpringBoot配置文件占位符

propertiesyaml配置文件中是可以使用占位符的

随机数

  • ${random.value} - 类似uuid的随机数,没有"-"连接
  • ${random.int} - 随机取整型范围内的一个值
  • ${random.long} - 随机取长整型范围内的一个值
  • ${random.long(100,200)} - 随机生成长整型100-200范围内的一个值
  • ${random.uuid} - 生成一个uuid,有短杠连接
  • ${random.int(10)} - 随机生成一个10以内的数
  • ${random.int(100,200)} - 随机生成一个100-200 范围以内的数

例子:

#user.username=${random.value}

#user.username=${random.int}

#user.username=${random.long}

#user.username=${random.uuid}

#user.username=${random.int(10)}

#user.username=${random.int(100,200)}

user.username=${random.long(100,200)}

 

属性配置占位符

  1. ${key:defaultValue},若key 不存在,则将defaultValue的值赋值给取值的对象。
  2. 可以在配置文件中引用前面配置过的属性(优先级前面配置过的这里都能用)。
  3. ${app.name:默认值}来指定找不到属性时的默认值。

占位符获取之前配置的值,如果没有可以是用:指定默认值

person.last‐name=张三${random.uuid}
person.age=${random.int}
person.birth=2017/12/15
person.boss=false
person.maps.k1=v1
person.maps.k2=14
person.lists=a,b,c
person.dog.name=${person.hello:hello}_dog
person.dog.age=15

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值