在properties
或yaml
配置文件中是可以使用占位符的
随机数
${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)}
属性配置占位符
${key:defaultValue}
,若key
不存在,则将defaultValue
的值赋值给取值的对象。- 可以在配置文件中引用前面配置过的属性(优先级前面配置过的这里都能用)。
- ${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