小编Cer*_*rin的帖子

无法从application.yml加载属性

我想从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)

java spring spring-boot

2
推荐指数
1
解决办法
880
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1