评估Spring Expression Lang(SpEL)中的属性

我们的服务有一个根据属性文件安排的进程,读取属性refreshIntervalMillis 。 它的值直接在Quartz触发器中注入,具有以下配置:

 ...  

但是,安装此服务的管理员会考虑小时/天,因此为了使事情变得更容易,我们将其更改为:

  1. refreshIntervalMillis重命名为refreshIntervalMinutes
  2. 更改为上面的代码到以下内容:
 p:repeatInterval =“#{1000 * 60 * T(java.lang.Integer).valueOf(@configurationProperties ['garbageLevelWatcher.refreshIntervalMinutes'])}”

注意:属性对象公开为名为“configurationProperties”的bean

是否有更简单的语法来实现相同的目标?

谢谢,

"#{T(java.util.concurrent.TimeUnit).MINUTES.toMillis( @configurationProperties['garbageLevelWatcher.refreshIntervalMinutes'])}"

编辑:

要么…

  

 "#{@MINUTES.toMillis(${garbageLevelWatcher.refreshIntervalMinutes})}" 

如果属性由PropertyPlaceholderConfigurer,@ PropertySource或查找,并且上下文知道它

你可以像这样写:

 p:repeatInterval="#{ 1000 * 60 * T(java.lang.Integer).valueOf('${garbageLevelWatcher.refreshIntervalMinutes}') }"