apollo配置json
#json串原文
[
{"username":"李小刚","sex":"男"},
{"username":"苗翠花","sex":"女"}
]
public class MyDTO { private String username; private String sex; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } @Override public String toString() { return "MyDTO{" + "username='" + username + '\'' + ", sex='" + sex + '\'' + '}'; } }
import com.alibaba.fastjson.JSON; @Value("${my.testJson:''}") private String testJson; @PostConstruct public void init(){ List<MyDTO> activities = JSON.parseArray(testJson,MyDTO.class); for (int i=0;i<activities.size(); i++){ logger.info("MyDTO=[{}]", activities.get(i).toString()); } }
Apollo配置
my.testJson = [\n{"username":"李小刚","sex":"男"},\n{"username":"苗翠花","sex":"女"}\n]
##日志输出打印:
2023-03-27 22:58:21.174 [main] INFO [,] c.a.i.conf.MyConfigure#init [line:98] - MyDTO=[MyDTO{username='李小刚', sex='男'}]
2023-03-27 22:58:21.174 [main] INFO [,] c.a.i.conf.MyConfigure#init [line:98] - MyDTO=[MyDTO{username='苗翠花', sex='女'}]