@ConfigurationProperties 默认从全局配置文件(application.properties/application.yml)中获取值,
所有配置数据写在全局配置文件中,显得太臃肿了, 可将它们抽取出来,放到其他局部配置文件中
1. 将 全局配置文件 中的emp相关配置数据 抽取 到 resources/ emp.properties 文件中
2. @PropertySource :加载指定的配置文件; value 属性是数组类型, 用于指定文件位置
@PropertySource(value = {"classpath:emp.properties"})
@Component
public class Emp {
private String lastName;
private Integer age;
private Double salary;
private Boolean boss;
private Date birthday;
private Map map;
private List list;
private Forte forte;
@Override
public String toString() {
return "Emp{" +
"lastName='" + lastName + '\'' +
", age=" + age +
", salary=" + salary +
", boss=" + boss +
", birthday=" + birthday +
", map=" + map +
", list=" + list +
", forte=" + forte +
'}';
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
public Boolean getBoss() {
return boss;
}
public void setBoss(Boolean boss) {
this.boss = boss;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Map getMap() {
return map;
}
public void setMap(Map map) {
this.map = map;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public Forte getForte() {
return forte;
}
public void setForte(Forte forte) {
this.forte = forte;
}
}
emp.properties文件配置
#编辑emp的数据
emp.last-name=李四
emp.age=30
emp.birthday=1989/9/12
emp.boss=false
emp.salary=23000
emp.map.key1=value1
emp.map.key2=value2
emp.list=one, two, three
emp.forte.name=python
emp.forte.time=5