@PropertySources和@ConfiguratrionProperties组合使用注入外部文件配置
在classpath下新建一个user.properties配置文件
my.app.id = 1
my.app.name = zhangsan
my.app.sex = man
新建一个user类
@Component
@PropertySource(“classpath:user.properties”)
@ConfigurationProperties(prefix = “my.app”)
public class User {
private Integer id;
private String name;
private String sex;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +