![在这里插入图片描述](https://img-blog.csdnimg.cn/fb8cfe4d43df44da88aaa06728d47e09.png)
一、三种配置格式
![在这里插入图片描述](https://img-blog.csdnimg.cn/7c3060c42c6246ecbdfe6d0dfe86591b.png)
配置文件的优先级
共存叠加并相互覆盖
![在这里插入图片描述](https://img-blog.csdnimg.cn/8bdad4027785425fa9a9bf40c66b5397.png)
二 yml配置文件的数据格式
![在这里插入图片描述](https://img-blog.csdnimg.cn/cc91199cf9054008b07c9d457918c4e5.png)
2.1 常见数组和对象的yml格式
![在这里插入图片描述](https://img-blog.csdnimg.cn/939c05a72c6f4864b7d4a5d757811ee3.png)
2.2 读取yml单一数据
![在这里插入图片描述](https://img-blog.csdnimg.cn/f397ffc82bdd4a6e8a72a3282df637ea.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/c32a4c78c29f4b06a398403b2568c5e6.png)
访问http://localhost:8080/books,控制台输出
![在这里插入图片描述](https://img-blog.csdnimg.cn/a3ce5d7512b0489a900272408da3cb9c.png)
2.3 将数据封装到Environment对象中
![在这里插入图片描述](https://img-blog.csdnimg.cn/f746921274de415dad19d023bde5ca0a.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/fed538db68b24f34b1f79162d8c0e6dd.png)
此处的@Autowired注解通过自动装配,把所有的数据都封装到了Envirment这个对象中,使用getPropertry方法得到数据。
2.4 读取yml引用类型属性数据(重点! springboot主流方式)
在配置文件中:![在这里插入图片描述](https://img-blog.csdnimg.cn/5b670ffad74f458392e84d57a312ea42.png)
1.创建类,封装数据
![在这里插入图片描述](https://img-blog.csdnimg.cn/06beb77b40ef4528b194b8ee21d581f3.png)
2.直接获取信息使用:
![在这里插入图片描述](https://img-blog.csdnimg.cn/bf1a1fc5f8204e748a57b7d9c1172962.png)
![在这里插入图片描述](https://img-blog.csdnimg.cn/8dec41b890d4447498d001a483958fff.png)