gpt4 book ai didi

java - 在非字符串注释字段 spring 中使用 yml 文件中的值

转载 作者:行者123 更新时间:2023-12-01 18:05:25 25 4
gpt4 key购买 nike

我想在注释字段中使用配置值,字段不是字符串。例如我有:

@Document(indexName = "#{@transactionIndexName}", shards = 1, 
refreshInterval = "2s", versionType = VersionType.EXTERNAL)

所以在indexName中我使用了spring spel,但是分片是短类型值,那么我如何使用yml文件中的设置?

最佳答案

您应该能够在 Spel 表达式中将 shards 值从 String 转换为 short,如下所示:

#{T(java.lang.Short).parseShort(${transaction.shards})}

...当然假设您的属性(property)是 transaction.shards

我目前无法对此进行测试,但我相信这应该可行。

关于java - 在非字符串注释字段 spring 中使用 yml 文件中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60566324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com