6

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

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

但是,安装此服务的管理员会考虑小时/天数,因此为了让他们更轻松,我们将其更改为:

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

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

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

谢谢,

4

2 回答 2

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

"#{@MINUTES.toMillis(${garbageLevelWatcher.refreshIntervalMinutes})}"
于 2013-03-19T21:47:56.283 回答
1

如果属性由 PropertyPlaceholderConfigurer、@PropertySource 或 <context:property-placeholder /> 查找并且上下文知道它

你可以这样写:

p:repeatInterval="#{ 1000 * 60 * T(java.lang.Integer).valueOf('${garbageLevelWatcher.refreshIntervalMinutes}') }"
于 2013-03-19T21:15:58.197 回答