博客
关于我
SpringBoot | 读取yaml配置文件并注入JavaBean
阅读量:373 次
发布时间:2019-03-04

本文共 1508 字,大约阅读时间需要 5 分钟。

???Spring Boot?????YAML??????????

?Spring Boot???????????????????????????????????????????????????????YAML???????????

1. ???????

???????????pom.xml?????Spring Boot?????????????????????????????????????

org.springframework.boot
spring-boot-configuration-processor

2. ?Person?????

????????????Person??????????????????????????????@Component?@ConfigurationProperties???

@Component@ConfigurationProperties(prefix = "person")public class Person {    public String name;    public int age;    public Date birthday;    public Map
map; public List
list;}
  • @Component????????????Spring?IOC????
  • @ConfigurationProperties(prefix = "person")?????????????????????person??????????

3. ????

??????????????Person??????@Autowired????????????????????????

import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;@SpringBootTestpublic class DemoApplicationTests {    @Autowired    private Person person;    @Test    void contextLoads() {        System.out.println("?????" + person);    }}

4. ??????

????????????????????????????????????????

Person{name='zhangsan', age=20, birthday=Sun Nov 01 00:00:00 CST 2020, map={k1=v1, k2=v2}, list=[aaa, bbb, ccc]}

5. ??????

?resources????????applications.yml????????

person:  name: zhangsan  age: 20  birthday: 2020/11/1  map:    k1: v1    k2: v2  list:    - aaa    - bbb    - ccc

??????????????????????????????Person????????????????????????????????????????????

转载地址:http://yayg.baihongyu.com/

你可能感兴趣的文章
Objective-C实现Factorial digit sum阶乘数字和算法(附完整源码)
查看>>
Objective-C实现factorial iterative阶乘迭代算法(附完整源码)
查看>>
Objective-C实现factorial recursive阶乘递归算法(附完整源码)
查看>>
Objective-C实现factorial阶乘算法(附完整源码)
查看>>
Objective-C实现Fast Powering算法(附完整源码)
查看>>
Objective-C实现Fedwick树算法(附完整源码)
查看>>
Objective-C实现fenwick tree芬威克树算法(附完整源码)
查看>>
Objective-C实现FenwickTree芬威克树算法(附完整源码)
查看>>
Objective-C实现FermatPrimalityTest费马素数测试算法(附完整源码)
查看>>
Objective-C实现fft2函数功能(附完整源码)
查看>>
Objective-C实现FFT快速傅立叶变换算法(附完整源码)
查看>>
Objective-C实现FFT算法(附完整源码)
查看>>
Objective-C实现fibonacci search斐波那契查找算法(附完整源码)
查看>>
Objective-C实现fibonacci斐波那契算法(附完整源码)
查看>>
Objective-C实现FigurateNumber垛积数算法(附完整源码)
查看>>
Objective-C实现finding bridges寻找桥梁算法(附完整源码)
查看>>
Objective-C实现first come first served先到先得算法(附完整源码)
查看>>
Objective-C实现Gale-Shapley盖尔-沙普利算法(附完整源码)
查看>>
Objective-C实现getline函数功能(附完整源码)
查看>>
Objective-C实现gnome sortt侏儒排序算法(附完整源码)
查看>>