内容纲要
SpringBoot从Yml文件读取配置
注解方法
@ConfigurationProperties(prefix = "spring.arr")
@Data
注意
@Data
注解,从Yml读取配置映射到类上时一定要有set
方法,不然读不到。
从Yml文件读取列表
spring:
arr:
pinfo:
- name: gaf11
age: 11
school: scu
- name: gaf22
age: 22
school: scu
- name: gaf33
age: 33
school: scu
@Data
public class Pinfo {
String name;
Integer age;
String school;
}
@ConfigurationProperties(prefix = "spring.arr")
@Component
@Data
public class ReadArr {
List<Pinfo> pinfo;
ReadArr(){}
public List<Pinfo> getList(){
return pinfo;
}
}