在我们的开发中,有很多配置文件是需要分开配置的,例如kafka.properties,amq.properties等,那这些自定义的配置文件,怎么加载到对应的类里面了,下面就来说说这个问题。
在src/main/resources目录下新建一个config文件夹,用来存放我们的properties文件。目录结构如下:
user.properties配置文件内容如下:
com.chhliu.springboot.author=xyy
com.chhliu.springboot.age=${com.chhliu.age}
com.chhliu.springboot.sex=woman
com.chhliu.springboot.time=20170123
com.chhliu.age=27
对应的配置类如下:
public class ConfigProperties {
private String author;
private int age;
private String sex;
private String time;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getAge() {
return age;
}
public void setAge(int ag