Grails 3 使用“.”解析哈希映射属性in key 在早期版本中没有按预期工作

Grails 3 parsing of hash map properties with "." in key not working as expected in earlier versions

我们的多租户应用程序有以下 属性,可帮助我们根据域找到租户。

mydomains = [
  'www.google.com': 'tenant1',
  'www.abc.com': 'tenant2'
]

在 grails2.2.4 中我们可以访问它

grailsApplication.config.mydomains['www.abc.com']

它会在 2.2.4 中正确地给我们 'tenant2',但在 grails 3.3.7 中它似乎为每个“.”创建了一个映射。在密钥中,因此无法找到给定域的租户。以下是 mydomains 属性 在 3.3.7

中的解析方式
[www:[google:[com:tenant1], abc:[com:tenant2]]]

有没有一种方法可以让我在 3.3.7 中获得相同的行为?

而不是 grailsApplication.config.mydomains['www.abc.com'] 使用 grailsApplication.config.getProperty('mydomains.www.abc.com').

顺便说一句...这与您的问题没有直接关系,但在极少数情况下直接引用 grailsApplication.config 确实是最好的做法。有关详细信息,请参阅 https://objectcomputing.com/resources/publications/sett/retrieving-config-values-in-grails-3 and the video at https://objectcomputing.com/products/grails/quickcasts/runtime-config-values-grails-3 上的文章。在视频中,我讨论了直接访问 grailsApplication.config 通常不是最好的一些原因。

希望对您有所帮助。