springbootyml或properties配置list

编程

1 配置定义 

appliction.properties

app.limiter.data[0].key=hello1

app.limiter.data[0].time=MIIBIjsdfsdf2t24aAFEGDsef

app.limiter.data[0].count=MIIEvDGdfgtertsf

app.limiter.data[1].key=hello2

app.limiter.data[1].time=MIIBIjsdfsdf2t24aAFEGDsef

app.limiter.data[1].count=MIIEvDGdfgtertsf

application.yml

app:

limiter:

data[0]:

key: hello

time: MIIBIjsdfsdf2t24aAFEGDsef

count: MIIEvDGdfgtertsf

data[1]:

key: hello1

time: MIIBIjsdfsdf2t24aAFEGDsef

count: MIIEvDGdfgtertsf

2. 读取配置文件

@Configuration

@ConfigurationProperties(prefix = "app.limiter")

public class LimiterProperties {

private List<LimiterProp> data;

public List<LimiterProp> getData() {

return data;

}

public void setData(List<LimiterProp> data) {

this.data = data;

}

public static class LimiterProp {

private String key;

private String time;

private String count;

public String getKey() {

return key;

}

public void setKey(String key) {

this.key = key;

}

public String getTime() {

return time;

}

public void setTime(String time) {

this.time = time;

}

public String getCount() {

return count;

}

public void setCount(String count) {

this.count = count;

}

}

}

以上是 springbootyml或properties配置list 的全部内容, 来源链接: utcz.com/z/519154.html

回到顶部