Spring Boot基础3-配置文件详解:Properties和YAML
来源:互联网 发布:最小割算法 编辑:程序博客网 时间:2024/05/16 10:24
源码地址:https://github.com/roncoo/spring-boot-demo
一.配置文件的生效顺序,会对值进行覆盖:
1. @TestPropertySource 注解
2. 命令行参数
3. Java系统属性(System.getProperties())
4. 操作系统环境变量
5. 只有在random.*里包含的属性会产生一个RandomValuePropertySource
6. 在打包的jar外的应用程序配置文件(application.properties,包含YAML和profile变量)
7. 在打包的jar内的应用程序配置文件(application.properties,包含YAML和profile变量)
8. 在@Configuration类上的@PropertySource注解
9. 默认属性(使用SpringApplication.setDefaultProperties指定)
二.配置随机值
roncoo.secret=${random.value}
roncoo.number=${random.int}
roncoo.bignumber=${random.long}
roncoo.number.less.than.ten=${random.int(10)}
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属性文件,按优先级排序,位置高的将覆盖位置低的
1. 当前目录下的一个/config子目录
2. 当前目录
3. 一个classpath下的/config包
4. 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基础3-配置文件详解:Properties和YAML
- Spring Boot-配置文件详解:Properties和YAML
- Spring Boot-配置文件详解:Properties和YAML
- spring boot之Properties和YAML
- Spring Boot配置文件application properties配置详解
- Spring boot 切换配置文件到yaml
- spring-boot(0) application.properties配置文件和自定义配置文件
- Spring Boot系列教程四:配置文件详解properties
- Spring Boot系列教程四:配置文件详解properties
- Spring boot配置文件 application.properties
- Spring boot配置文件 application.properties
- Spring Boot配置文件 application.properties
- [Spring boot]配置文件properties加载
- spring boot配置文件application.properties
- Spring boot配置文件application.properties
- spring boot配置文件application.properties
- spring Boot 配置文件详解
- spring boot 配置文件详解
- java内存模型和线程
- 什么是计算机图形学?
- 【软考之用例图再分析】
- C语言学习——有头链表
- MFCC倒谱系数
- Spring Boot基础3-配置文件详解:Properties和YAML
- android中传递复杂参数,activity之间和fragment之间的bundle传递集合/对象
- Linux文件读写机制及优化方式
- tcpdump命令详解
- ie浏览器兼容
- myeclipse10破解
- oracle中number类型 默认长度是多少
- 读取与解析XML数据(SAX、DOM、PULL)
- bat脚本_WINDOWS命令和批处理