Spring Boot-配置文件详解:Properties和YAML
2017-09-13 11:22
513 查看
一、配置文件的生效顺序,会对值进行覆盖:
@TestPropertySource 注解命令行参数
Java系统属性(System.getProperties())
操作系统环境变量
只有在random.*里包含的属性会产生一个RandomValuePropertySource
在打包的jar外的应用程序配置文件(application.properties,包含YAML和profile变量)
在打包的jar内的应用程序配置文件(application.properties,包含YAML和profile变量)
在@Configuration类上的@PropertySource注解
默认属性(使用SpringApplication.setDefaultProperties指定)
二.配置随机值
1、roncoo.secret=${random.value}2、roncoo.number=${random.int}
3、roncoo.bignumber=${random.long}
4、roncoo.number.less.than.ten=${random.int(10)}
5、roncoo.number.in.range=${random.int[1024,65536]}
读取使用注解:@Value(value = “${roncoo.secret}”);注:出现黄点提示,是要提示配置元数据,可以不配置
三.属性占位符
当application.properties里的值被使用时,它们会被存在的Environment过滤,所以你能够引用先前定义的值(比如,系统属性)。roncoo.name=www.roncoo.com
roncoo.desc=${roncoo.name} is a domain name
四.Application属性文件,按优先级排序,位置高的将覆盖位置低的
当前目录下的一个/config子目录当前目录
一个classpath下的/config包
classpath根路径(root)
这个列表是按优先级排序的(列表中位置高的将覆盖位置低的)
五. 配置应用端口和其他配置的介绍
#端口配置:server.port=8090
#时间格式化
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#时区设置
spring.jackson.time-zone=Asia/Chongqing
六. 使用YAML代替Properties
注意写法:冒号后要加个空格相关文章推荐
- Spring Boot 配置文件详解:Properties和YAML
- Spring Boot 配置文件详解:Properties和YAML
- Spring Boot系列教程四:配置文件详解properties
- (三)SpringBoot之配置文件详解:Properties和YAML
- Spring Boot -- 配置文件详解:Properties 和 YAML
- 004,配置文件详解:Properties和YAML
- (三)SpringBoot之配置文件详解:Properties和YAML
- Spring Boot系列教程四:配置文件详解properties
- Spring Boot-配置文件详解:Properties和YAML
- Spring Boot基础3-配置文件详解:Properties和YAML
- freemaker中配置文件freemarker.properties详解
- struts2的struts.properties配置文件详解
- log4j.properties配置文件详解
- freemaker中配置文件freemarker.properties详解
- struts2的struts.properties配置文件详解
- kafka配置文件详解之:server.properties
- struts.properties配置文件详解
- Storm的配置文件yaml详解
- Struts2的struts.properties配置文件属性详解
- struts2的struts.properties配置文件详解