概述
编写规则
1、大小写敏感,同json;
2、通过缩进表示层级关系;
符号含义
先写个注意事项:字符串默认不需要加上单引号或双引号。
#:用于注释;
“”:不会转义特殊字符,表示字符串本身想表达的意思,如name: ‘aaa n bbb’ :输出 aaa 换行 bbb
‘’:会转义字符,如name: ‘aaa n bbb’:输出;aaa n bbb
对象
animal: pets
hash: { name: Steve, foo: bar }
对应json:
{
{ "animal": "pets" },
{ "hash": { "name": "Steve", "foo": "bar" } }
}
数组
Animal:
- Cat
- Dog
- Goldfish
对应json:
{ "Animal": [ "Cat", "Dog", "Goldfish" ] }
字符串
# 正常情况下字符串不用写引号
str: 这是一行字符串
# 字符串内有空格或者特殊字符时需要加引号
str: '内容: 字符串'
null
parent: ~
对应json:
{ "parent": null }
Spring Boot中
@Value获取值和@ConfigurationProperties获取值比较;
@PropertySource&@ImportResource&@Bean;
@PropertySource:加载指定的配置文件;
@ImportResource:导入Spring的配置文件,让配置文件里面的内容生效;
Spring Boot里面没有Spring的配置文件,我们自己编写的配置文件,也不能自动识别;
想让Spring的配置文件生效,加载进来;@ImportResource标注在一个配置类上
SpringBoot推荐给容器中添加组件的方式;推荐使用全注解的方式
配置类@Configuration------>Spring配置文件
使用@Bean给容器中添加组件
配置文件加载位置
springboot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文
件
–file:./config/
–file:./
–classpath:/config/
–classpath:/
优先级由高到底,高优先级的配置会覆盖低优先级的配置。
最后
以上就是乐观墨镜为你收集整理的yml语法规则(spring boot配置文件)的全部内容,希望文章能够帮你解决yml语法规则(spring boot配置文件)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复