Spring Boot属性配置文件详解
来源:互联网 发布:windows 全屏快捷键 编辑:程序博客网 时间:2024/06/06 21:42
Spring Boot属性配置文件详解
1 自定义属性
2 属性引用
com.didispace.blog.name=程序猿DD
com.didispace.blog.title=Spring Boot教程
com.didispace.blog.desc=${com.didispace.blog.name}正在努力写《${com.didispace.blog.title}》
3 随机数
# 随机字符串
com.didispace.blog.value=${random.value}
# 随机int
com.didispace.blog.number=${random.int}
# 随机long
com.didispace.blog.bignumber=${random.long}
# 10以内的随机数
com.didispace.blog.test1=${random.int(10)}
# 10-20的随机数
com.didispace.blog.test2=${random.int[10,20]}
4 命令行设置属性
命令:java -jar xxx.jar --server.port=8888,通过使用–server.port属性来设置xxx.jar应用的端口为8888。
在命令行运行时,连续的两个减号--就是对application.properties中的属性值进行赋值的标识。
只需要这句设置就能屏蔽命令行设置属性值:SpringApplication.setAddCommandLineProperties(false)。
5 多环境配置
在Spring Boot中多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对应你的环境标识,比如:
application-dev.properties:开发环境
application-test.properties:测试环境
application-prod.properties:生产环境
至于哪个具体的配置文件会被加载,需要在application.properties文件中通过spring.profiles.active属性来设置,其值对应{profile}值。
如:spring.profiles.active=test就会加载application-test.properties配置文件内容
1 自定义属性
2 属性引用
com.didispace.blog.name=程序猿DD
com.didispace.blog.title=Spring Boot教程
com.didispace.blog.desc=${com.didispace.blog.name}正在努力写《${com.didispace.blog.title}》
3 随机数
# 随机字符串
com.didispace.blog.value=${random.value}
# 随机int
com.didispace.blog.number=${random.int}
# 随机long
com.didispace.blog.bignumber=${random.long}
# 10以内的随机数
com.didispace.blog.test1=${random.int(10)}
# 10-20的随机数
com.didispace.blog.test2=${random.int[10,20]}
4 命令行设置属性
命令:java -jar xxx.jar --server.port=8888,通过使用–server.port属性来设置xxx.jar应用的端口为8888。
在命令行运行时,连续的两个减号--就是对application.properties中的属性值进行赋值的标识。
只需要这句设置就能屏蔽命令行设置属性值:SpringApplication.setAddCommandLineProperties(false)。
5 多环境配置
在Spring Boot中多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对应你的环境标识,比如:
application-dev.properties:开发环境
application-test.properties:测试环境
application-prod.properties:生产环境
至于哪个具体的配置文件会被加载,需要在application.properties文件中通过spring.profiles.active属性来设置,其值对应{profile}值。
如:spring.profiles.active=test就会加载application-test.properties配置文件内容
阅读全文
0 0
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- Spring Boot属性配置文件详解
- SpringBoot(3) Spring Boot属性配置文件详解
- Chapter2 Spring Boot属性配置文件详解
- Spring Boot属性配置文件
- spring boot 配置文件属性
- spring Boot 配置文件详解
- spring boot 配置文件详解
- Spring Boot配置文件详解
- 传统命名网卡名字
- 一个简单的string类构造
- java业务常用排序方法
- Html表单提交到Servlet输出到页面乱码 Html使用的编码是UTF-8编码显示页面,之后使用form表单提交字段到Servlet中,Servlet将利用getParamer方法获得fo
- wireshark分析UDP数据包
- Spring Boot属性配置文件详解
- 行指针与列指针_1
- 静态局部变量和全局变量的区别!
- 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。
- Java数据交互管道——IO流(输入输出流详解)
- 解决The JAVA_HOME environment variable is not defined correctly
- 【转载】不要做浮躁的嵌入式系统工程师
- 体验traceroute
- C++ 算法问题解决