评估Spring表达式Lang(SpEL)中的属性 [英] Evaluating properties inside Spring Expression 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:
- 将 refreshIntervalMillis 重命名为 refreshIntervalMinutes
- 更改为以下代码:
- Renamed refreshIntervalMillis to refreshIntervalMinutes
- 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屋!