springBoot之yml文件的基本语法+映射到bean的实例

本文介绍了SpringBoot中yml文件的基本语法,包括数字、布尔、字符串、对象、Map和数组类型的使用,并通过实例展示了如何将yml配置映射到Bean。同时,文中提及了在pom配置以及测试类中的操作,还讨论了.properties文件中文乱码的解决方案。
摘要由CSDN通过智能技术生成

1,基本案例

2,数字、布尔、字符串类型

3,对象、map类型

4,数组类型(list/set)

5,映射到bean实例

pom中加上如下配置

<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
		<dependency>
			<groupId>org.s
回答: SpringBoot在启动加载配置文件时,默认会加载application.yml或application.properties文件,如果没有明确指定spring.profiles.active属性。\[1\]如果你的项目是一个SpringBoot项目而不是SpringCloud项目,只会识别application.yml配置文件,不会读取bootstrap.yml/properties文件。\[2\]如果想在SpringBoot项目中使用bootstrap.yml配置,需要添加依赖spring-cloud-context。\[2\]在yml文件中,key: value的冒号后面需要有一个空格。\[3\]如果想让SpringBoot加载自定义的yml配置文件,可以使用@PropertySource注解和@Value注解来指定目标属性在yml文件中的全限定名。同时,需要将目标类标记为@Component,以将其实例化到Spring容器中。\[3\] #### 引用[.reference_title] - *1* *2* [springcloud+springboot框架 动态加载配置文件 bootstrap.yml/properties文件](https://blog.csdn.net/qq_40448069/article/details/124929353)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Springboot加载自定义yml文件配置的方法](https://blog.csdn.net/u010922732/article/details/91048606)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值