Spring Boot配置随机数
Spring Boot支持在系统加载的时候配置随机数。
添加config/random.properties文件,添加以下内容:
#随机32位MD5字符串
user.random.secret=${random.value}
#随机int数字
user.random.intNumber=${random.int}
#随机long数字
user.random.longNumber=${random.long}
#随便uuid
user.random.uuid=${random.uuid}
#随机10以内的数字
user.random.lessTen=${random.int(10)}
#随机1024~65536之内的数字
user.random.range=${random.int[1024,65536]}
添加绑定类:
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "user.random")
@PropertySource(value = { "config/random.properties" })
public class RandomConfig {
private String secret;
private int intNumber;
private int lessTen;
private int range;
private long longNumber;
private String uuid;
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public int getIntNumber() {
return intNumber;
}
public void setIntNumber(int intNumber) {
this.intNumber = intNumber;
}
public int getLessTen() {
return lessTen;
}
public void setLessTen(int lessTen) {
this.lessTen = lessTen;
}
public int getRange() {
return range;
}
public void setRange(int range) {
this.range = range;
}
public long getLongNumber() {
return longNumber;
}
public void setLongNumber(long longNumber) {
this.longNumber = longNumber;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
输出如下:
secret=83a5c3402ef936a37842dc6de3d1af0f
intNumber=1816149855
lessTen=1
range=37625
longNumber=8449008776720010146
uuid=e5bc2091-1599-45b1-abd7-e3721ac77e6b
具体的生成细节可以参考Spring Boot的配置类:
org.springframework.boot.context.config.RandomValuePropertySource
推荐阅读
分享Java干货,高并发编程,热门技术教程,微服务及分布式技术,架构设计,区块链技术,人工智能,大数据,Java面试题,以及前沿热门资讯等。
Spring Boot配置随机数的更多相关文章
- Spring Boot 配置随机数技巧
Spring Boot支持在系统加载的时候配置随机数. 添加config/random.properties文件,添加以下内容: #随机32位MD5字符串 user.random.secret=${r ...
- Spring Boot -- 配置切换指南
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- Spring Boot 配置优先级顺序
一般在一个项目中,总是会有好多个环境.比如: 开发环境 -> 测试环境 -> 预发布环境 -> 生产环境 每个环境上的配置文件总是不一样的,甚至开发环境中每个开发者的环境可能也会有一 ...
- spring boot 配置注入
spring boot配置注入有变量方式和类方式(参见:<spring boot 自定义配置属性的各种方式>),变量中又要注意静态变量的注入(参见:spring boot 给静态变量注入值 ...
- Spring boot配置多个Redis数据源操作实例
原文:https://www.jianshu.com/p/c79b65b253fa Spring boot配置多个Redis数据源操作实例 在SpringBoot是项目中整合了两个Redis的操作实例 ...
- spring boot配置springMVC拦截器
spring boot通过配置springMVC拦截器 配置拦截器比较简单, spring boot配置拦截器, 重写preHandle方法. 1.配置拦截器: 2重写方法 这样就实现了拦截器. 其中 ...
- spring boot配置mybatis和事务管理
spring boot配置mybatis和事务管理 一.spring boot与mybatis的配置 1.首先,spring boot 配置mybatis需要的全部依赖如下: <!-- Spri ...
- [转] Spring Boot配置多个DataSource
[From] https://www.liaoxuefeng.com/article/001484212576147b1f07dc0ab9147a1a97662a0bd270c20000 Sprin ...
- Spring boot 配置异步处理执行器
示例如下: 1. 新建Maven 项目 async-executor 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...
随机推荐
- thymeleaf数组下标
<tr th:if="${exercisers != null}"th:each="exerciser:${exercisers}"> <td ...
- springCloud的使用01-----服务的注册和发现
1 搭建eureka注册服务器 1.1 创建springboot项目,导入相应的jar包依赖 <project xmlns="http://maven.apache.org/POM/4 ...
- linux下又一次定位svn url方法
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/oudahe/article/details/34437661 linux下又一次定位svn url方 ...
- 多线程实现奇偶统计v2 - 信号量实现
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "pthread.h& ...
- 案例-3D旋转木马
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- AtCoder Grand Contest 001F Wide Swap
解法参考这位大佬的:https://www.cnblogs.com/BearChild/p/7895719.html 因为原来的数组不好做于是我们想反过来数组,根据交换条件:值相邻且位置差大于等于k, ...
- 热修复框架Tinker的从0到集成之路(转)
转自:http://blog.csdn.net/lisdye2/article/details/54411727 热修复框架Tinker的从0到集成之路 转载请标明出处: http://blog.cs ...
- openwrt ssh免密登录
1 生成相关秘钥 dropbearkey -t rsa -f id_rsa dropbearkey -y -f id_rsa | grep "^ssh-rsa" >> ...
- JS判断浏览器类型的方法总结(IE firefox chrome opera safari)
JS判断浏览器类型的方法总结,可判别当前客户端所使用的浏览器是ie,firefox,safari,chrome或者是opera,另外js可以精确判断到ie浏览器的版本,依然直接上代码,需要的朋友可按照 ...
- 关于C#中Convert.ToInt32()是干什么用的
并非每个对象都可以直接转换为int.例如,以下内容将无法编译: string Maomao = "100"; int i = (int)Maomao; 因为string无法隐式转换 ...