博客
关于我
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实现Http协议下载文件(附完整源码)
查看>>
Objective-C实现IIR 滤波器算法(附完整源码)
查看>>
Objective-C实现IIR数字滤波器(附完整源码)
查看>>
Objective-C实现insertion sort插入排序算法(附完整源码)
查看>>
Objective-C实现integer partition整数分区算法(附完整源码)
查看>>
Objective-C实现integerPartition整数划分算法(附完整源码)
查看>>
Objective-C实现interpolation search插值搜索算法(附完整源码)
查看>>
Objective-C实现Interpolation search插值查找算法(附完整源码)
查看>>
Objective-C实现intersection交集算法(附完整源码)
查看>>
Objective-C实现intro sort内省排序算法(附完整源码)
查看>>
Objective-C实现inversions倒置算法(附完整源码)
查看>>
Objective-C实现isalpha函数功能(附完整源码)
查看>>
Objective-C实现islower函数功能(附完整源码)
查看>>
Objective-C实现isPowerOfTwo算法(附完整源码)
查看>>
Objective-C实现ItemCF算法(附完整源码)
查看>>
Objective-C实现ItemCF算法(附完整源码)
查看>>
Objective-C实现iterating through submasks遍历子掩码算法(附完整源码)
查看>>
Objective-C实现jaccard similarity相似度无平方因子数算法(附完整源码)
查看>>
Objective-C实现Julia集算法(附完整源码)
查看>>
Objective-C实现k nearest neighbours k最近邻分类算法(附完整源码)
查看>>