Spring Boot -- 配置文件详解:Properties 和 YAML
2018-03-06 00:17
836 查看
配置文件的生效顺序,会对值进行覆盖
@TestPropertySource 注解命令行参数
Jave 系统属性(System.getProperties())
操作系统环境变量
只有在 random.* 里包含的属性会产生一个 RandomValuePropertySource
在打包的 jar 外的应用程序配置文件(application.properties,包含 YAML 和 profile 变量)
在打包的 jar 内的应用程序配置文件(application.properties,包含 YAML 和 profile 变量)
在 @Configuration 类上的@PropertySource 注解
默认属性(使用 SpringApplication.setDefaultproperties指定)
配置随机值
oktfolio.secret=${random.value}oktfolio.number=${random.int}
oktfolio.bignumber=${random.long}
oktfolio.number.less.than.ten=${random.int(10)}
oktfolio.number.in.range=${random.int[1024,65536]}
读取使用注解:@Value(value = “${oktfolio.secret}”)
注:出现黄点提示,提示配置元数据,可以不配置
属性占位符
当 application.properties 里的值被使用时,它们会被存在的 Environment 过滤,所以你能够引用先前定义的值(比如,兄属性)oktfolio.name = www.oktfolio.me
oktfolio.desc= ${oktfolio.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基础3-配置文件详解:Properties和YAML
- (三)SpringBoot之配置文件详解:Properties和YAML
- Spring Boot 配置文件详解:Properties和YAML
- (三)SpringBoot之配置文件详解:Properties和YAML
- Spring Boot-配置文件详解:Properties和YAML
- YAML/Properties配置文件与Spring Boot(转)
- Spring Boot系列教程四:配置文件详解properties
- Spring Boot系列教程四:配置文件详解properties
- 详解Spring Boot加载properties和yml配置文件
- Spring Boot 读取properties配置文件
- Spring Boot属性配置文件详解
- SpringBoot学习之配置文件注入@ConfigurationProperties
- spring boot application.properties文件外部配置
- spring Boot 配置文件详解
- springboot 修改默认加载的配置文件不为application.properties
- springboot 修改启动时默认加载application.properties文件以及加载指定配置文件
- Spring Boot系列教程五:使用properties配置文件实现多环境配置
- Spring Boot属性配置文件详解
- spring boot application properties配置详解