使用注解@ConfigurationProperties(prefix = “person”) 自动从yml中加载person的属性,注入类中
- 这是springboot特有的,这个很重要,源码里这个注解出现了很多次
application.yml配置文件
person:
name: chendong
age: 18
happy: true
birth: 1888/08/18
maps: {k1: v1,k2: v2}
lists:
- code
- music
- girl
dog:
name: wangcai
age: 5
person类
@ConfigurationProperties(prefix = "person") //自动从yml中加载person的属性,注入类中
public class Person {
private String name;
private Integer age;
private Boolean happy;
private Date birth;
private Map<String, Object> maps;
private List<Object> lists;
private Dog dog;
- person类会自动从yml中加载名为person的属性,注入类中