spring boot: ConfigurationProperties

读取配置信息

1.5 之前

@Component
@ConfigurationProperties(prefix = "user", locations= {"classpath:user.properties"})
public class UserConfig {
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    private int age;
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
}

 

1.5 之后

@Component
@PropertySource(value = { "classpath:user.properties" })
@ConfigurationProperties(prefix = "user")
public class UserConfig {

    private String username;
    private Integer age;
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
}

 

posted @ 2017-07-15 23:29  xiluhua  阅读(209)  评论(0编辑  收藏  举报