2012-03-07 70 views
1

我正在配置一个Spring任务调度器。jndi的弹簧任务调度器延迟

<task:scheduled-tasks scheduler="myScheduler"> 
     <task:scheduled ref="servicesConfigurationBean" method="loadResources" fixed-delay="300000" /> 
</task:scheduled-tasks> 

它工作正常。现在我想从JNDI查找中设置延迟值。所以,我试过如下:

<task:scheduled ref="servicesConfigurationBean" method="loadResources"> 
    <property name="fixed-delay"><ref local="servicesRefreshRate"/></property> 
</task:scheduled> 

但现在我得到以下异常:

[/WEB-INF/spring/applicationContext.xml]是无效的;嵌套异常是org.xml.sax.SAXParseException:cvc-complex-type.2.1:元素'task:scheduled'必须没有字符或元素信息项[children],因为该类型的内容类型是空的[/ WEB-INF /spring/applicationContext.xml]无效;嵌套异常是org.xml.sax.SAXParseException:cvc-complex-type.2.1:元素'task:scheduled'必须没有字符或元素信息项[children],因为该类型的内容类型为空。

我明白异常的原因,那么,我的问题是否存在可行的解决方案? 谢谢。

回答

1

使用<property>将不起作用,因为<task:scheduled>是一个宏,而不是一个bean定义。这两个工作非常不同。

尝试使用Spring-EL代替:

<task:scheduled ref="servicesConfigurationBean" 
       method="loadResources" 
       fixed-delay="#servicesRefreshRate" /> 

我还没有尝试过,但给它一展身手。

+1

谢谢,我不知道SpEL,但它正是我所期待的。现在是适当的RTFM的时候了。 :) – Carlo 2012-03-07 13:29:38