spring_reference/IV. Spring Boot features/23.1. Configuring random va...

12 lines
567 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 23.1. 配置随机值
RandomValuePropertySource在注入随机值比如密钥或测试用例时很有用。它能产生整数longs或字符串比如
```java
my.secret=${random.value}
my.number=${random.int}
my.bignumber=${random.long}
my.number.less.than.ten=${random.int(10)}
my.number.in.range=${random.int[1024,65536]}
```
random.int*语法是OPEN value (,max) CLOSE此处OPENCLOSE可以是任何字符并且valuemax是整数。如果提供max那么value是最小的值max是最大的值不包含在内