【问题标题】:Using Spring ConfigurationProperties to bind to Map of Enum and List properties使用 Spring ConfigurationProperties 绑定到 Enum 和 List 属性的 Map
【发布时间】:2021-09-16 14:45:02
【问题描述】:

我有以下配置对象

@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "doginfo")
public class DogConfig {
    private Map<BreedEnum, List<String>> attributes;
}

BreedEnum 在哪里:

public enum BreedEnum {
    PITBULL, CORGI, SHIBA
}

我想将application.properties中的以下属性绑定到DogConfig

doginfo.PITBULL.attributes[0]=attrP0
doginfo.PITBULL.attributes[1]=attrP1

doginfo.CORGI.attributes[0]=attrC0

当我的应用程序运行时,attributes 配置为空。如何正确实现这种绑定? 谢谢

【问题讨论】:

  • 你读过the docs吗?
  • @Eugene 我做到了。大多数情况下,我需要语法方面的帮助。

标签: java spring spring-boot maven


【解决方案1】:

以下应该有效:

doginfo.attributes.PITBULL[0]=attrP0
doginfo.attributes.PITBULL[1]=attrP1

【讨论】:

    猜你喜欢
    • 2015-08-11
    • 2019-03-03
    • 1970-01-01
    • 2017-06-02
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2018-08-22
    相关资源
    最近更新 更多