ConfigurationProperties导入配置数据

361 阅读1分钟

1、新建配置数据

author.name= wyf
author.age= 32

2、导入数据到类

@Component
//通过ConfigurationProperties加载properties文件内的配置,通过prefix属性指定properties的配置的前缀,通过locatins指定properties文件的位置
//例如:@ConfigurationProperties(prefix="author".locations={{"classpath:config/author.properties"}})
@ConfigurationProperties(prefix = "author")
public class AuthorSettings {
    private String name;
    private Long age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getAge() {
        return age;
    }

    public void setAge(Long age) {
        this.age = age;
    }
}