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

Seb*_*ian 6 java spring expression properties spring-el

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

<bean name="trigger"
    class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean "
    p:repeatInterval="${refreshIntervalMillis}"> 
...
</bean>
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

谢谢,

Gar*_*ell 7

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

编辑:

要么...

<context:property-placeholder properties-ref="configurationProperties"
<util:constant id = "MINUTES" static-field="java.util.concurrent.TimeUnit.MINUTES" />
Run Code Online (Sandbox Code Playgroud)

"#{@MINUTES.toMillis(${garbageLevelWatcher.refreshIntervalMinutes})}"
Run Code Online (Sandbox Code Playgroud)