评估Spring表达式Lang(SpEL)中的属性 [英] Evaluating properties inside Spring Expression Lang (SpEL)

查看:430
本文介绍了评估Spring表达式Lang(SpEL)中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Our service has a process that is scheduled according to a properties file, reading the property refreshIntervalMillis. Its value is injected directly in a Quartz trigger with this configuration:

<bean name="trigger"
    class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean "
    p:repeatInterval="${refreshIntervalMillis}"> 
...
</bean>

但是,安装此服务的管理员以小时/天为单位,所以为了使对于他们来说更容易,我们将其更改为:

However, the admins that install this service think in terms of hours/days, so in order to make thing easier for them, we changed this to:


  1. refreshIntervalMillis 重命名为 refreshIntervalMinutes

  2. 更改为以下代码:

  1. Renamed refreshIntervalMillis to refreshIntervalMinutes
  2. Changed to code above to the following:




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

注意:属性对象被公开为一个名为configurationProperties的bean

Note: the properties object is exposed as a bean named "configurationProperties"

有更简单的语法来完成相同的操作吗?

Is there a simpler syntax to accomplish the same?

谢谢,

推荐答案

#{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" />

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

这篇关于评估Spring表达式Lang(SpEL)中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆