[英]Use value from yml file in non string annotation field spring
I want to use configuration value in annotation field, field is not string.我想在注释字段中使用配置值,字段不是字符串。 For example i have:例如我有:
@Document(indexName = "#{@transactionIndexName}", shards = 1,
refreshInterval = "2s", versionType = VersionType.EXTERNAL)
So in indexName
i used spring spel, but shards is short type value, so how can i use here setting from yml file?所以在indexName
我使用了 spring indexName
,但 shards 是短类型值,那么我如何使用 yml 文件中的设置?
You should be able to convert your shards
value from a String
to a short
within a Spel expression with something like this:您应该能够将您的shards
值从String
转换为 Spel 表达式中的short
,如下所示:
#{T(java.lang.Short).parseShort(${transaction.shards})}
... assuming that your property is transaction.shards
of course. ...当然,假设您的财产是transaction.shards
。
I'm not able to test this at the moment, but I believe that should work.我目前无法对此进行测试,但我相信这应该可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.