我想从application.yml加载服务器属性到Configuration类.我看到很多人已经问过同样的问题,但没有一个对我有用:(请帮我弄清楚我错过了什么
@Configuration
@ConfigurationProperties("demo")
public class Democonfig {
private List<Archive> archive = new ArrayList<>();
public Democonfig(List<Archive> archive) {
this.archive = archive;
}
// Getter and setter
public static class Archive {
private String host;
private String database;
private String port;
public Archive(String host, String database, String port) {
this.host = host;
this.database = database;
this.port = port;
}
// Getters and setters
}
}
Run Code Online (Sandbox Code Playgroud)
application.yml
demo:
archive:
-
host: "localhost"
database: "archive1"
port: "27017"
-
host: "localhost"
database: "archive2"
port: "27017" …Run Code Online (Sandbox Code Playgroud)