具有不同键的Spring Boot应用程序属性

时间:2018-08-27 06:32:02

标签: java spring spring-boot

我该如何定义一个对象来按键读取我的application.mysql数据库:

swaw:
  stage: dev
  ip: x.x.x.x
  port: 3306
  databases:
    mysql:
      url: "jdbc:mysql://...."
      password:
        dba: AAA
        read: BBB
    mssql:
      url: "jdbc:mssql://...."
      password:
        dba: CCC
        read: DDD
    informix:
       ....

我尝试使用此对象:

@ConfigurationProperties(prefix = "swaw.databases")
public class Databases {

    private Map<String, DatabasesConfig> map;

    public static class DatabasesConfig {

        private String url;
        private Password password;
        //GETTER AND SETTER

我收到每个请求:{"ip":"1x.x.x.x","port":"3306","databases":null}

1 个答案:

答案 0 :(得分:0)

@emoleumassi -试试这个:

 @ConfigurationProperties(prefix = "databases")
    public class Databases {     

            private String url;
            private Password password;
            //GETTER AND SETTER
    }