IntelliJ Spring Boot use application.yml custom property array problem
My project is spring boot web. I write some custom properties in application.yml as below:
my:
servers:
- name: Linux1
ip: 192.168.12.3
- name: Linux2
ip: 192.168.12.4
I write some Java code to get the server list, but it still does not work. Does somebody know how to solve this problem?
@Component
@ConfigurationProperties(prefix="my")
public class AppProperties {
private List<Server> servers = new ArrayList<Server>();
public List<Server> getServers() {
return this.servers;
}
@Override
public String toString() {
return "Config{}";
}
public static class Server
{
private String name;
private String ip;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
@Override
public String toString() {
return "Server{" +
"name='" + name + '\'' +
", ip='" + ip + '\'' +
'}';
}
}
}
Please sign in to leave a comment.
My problem is solved.
application.yml
application.yml custom properties(array) with spring boot
https://blog.xuite.net/akira32/home/585962873