@ConfigurationProperties使用
@ConfigurationProperties( prefix = "hello.properties" ) public class MyProperties { private String myKey; private List<String> stringList; private Duration duration; public String getMyKey() { return myKey; } public void setMyKey(String myKey) { this.myKey = myKey; } public List<String> getStringList() { return stringList; } public void setStringList(List<String> stringList) { this.stringList = stringList; } public Duration getDuration() { return duration; } public void setDuration(Duration duration) { this.duration = duration; } @Override public String toString() { return "MyProperties{" + "myKey=‘" + myKey + ‘\‘‘ + ", stringList=" + stringList + ", duration=" + duration + ‘}‘; } }
prefix
属性是配置文件里的前缀,即配置文件中以前缀 + 变量名
的形式配置一条记录,来对应类中的一个变量,如下:
hello.properties.myKey=hello hello.properties.duration=20s hello.properties.string-list[0]=Acelin hello.properties.string-list[1]=nice
@ConfigurationProperties特点
hello.properties.myKey=hello hello.properties.mykey=hello hello.properties.my-key=hello hello.properties.my_key=hello hello.properties.MY_KEY=hello hello.properties.MY-KEY=hello
https://www.cnblogs.com/acelin/p/15167266.html