我正在使用 redis 快取。我的代碼中有
時間是硬編碼的
@RedisHash(timeToLive=60)
在 Applications.yml 檔案中,我想添加以下內容
throttle:
cache:
rate: 60
所以我可以有以下
@RedisHash(timeToLive="${throttle.cache.rate}")
但這失敗了,型別不匹配無法從字串轉換為長整數。所以我試過了
@RedisHash(timeToLive="#{new Long(}'${throttle.cache.rate}')")
但仍然因型別不匹配而失敗,無法從字串轉換為長整數。
uj5u.com熱心網友回復:
基本上,這是不可能的。為什么?因為注釋的值必須是編譯時常量。編譯器在編譯時只知道您將 a 傳遞String給僅接受long.
它只會long在您運行 Spring 應用程式時發生,但為時已晚,因為編譯器不知道這一點。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/344065.html
上一篇:Netbeans:意外例外
