如何编写spring @ConfigurationProperties类以读取第二级地图?

时间:2018-07-10 09:19:56

标签: spring spring-boot yaml

在Yaml中,我具有以下属性:

threadPools:
  poollA:
    size: 10
    maxSize: 20
 poolB:
    size: 20

如何编写@ConfigurationProperties类以将此配置映射为具有池配置的Map?

如果再有一个级别,这很容易:

threadPools:
  configs:
    poollA:
      size: 10
      maxSize: 20
    poolB:
      size: 20

和java(实际上是Kotlin)类:

@ConfigurationProperties("threadPools")
internal class ThreadPoolsProperties {

    val configs: Map<String, ThreadPoolConfig> = mutableMapOf()

    internal class ThreadPoolConfig {
        var size: Int = 10
        var maxSize: Int = 10
    }
}  

但是第一个例子呢?

0 个答案:

没有答案