【问题标题】:Spring boot application properties with different keys [duplicate]具有不同键的 Spring Boot 应用程序属性[重复]
【发布时间】:2019-02-01 15:49:56
【问题描述】:

我如何定义一个对象来按键读取我的 application.mysql-databases:

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}

【问题讨论】:

    标签: java spring spring-boot


    【解决方案1】:

    @emoleumassi - 试试这个:

     @ConfigurationProperties(prefix = "databases")
        public class Databases {     
    
                private String url;
                private Password password;
                //GETTER AND SETTER
        }
    

    【讨论】:

      猜你喜欢
      • 2019-12-26
      • 2018-03-15
      • 2014-05-13
      • 2014-01-07
      • 2014-08-13
      • 2018-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多