如何参数@Scheduled(FIXEDDELAY)使用Spring 3.0 EX pression语言? [英] How to parameterize @Scheduled(fixedDelay) with Spring 3.0 expression language?

查看:604
本文介绍了如何参数@Scheduled(FIXEDDELAY)使用Spring 3.0 EX pression语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Spring 3.0功能注释计划任务,我想设置FIXEDDELAY从我的配置文件参数,而不是硬接线到我的任务类,像目前...

When using the Spring 3.0 capability to annotate a scheduled task, I would like to set the fixedDelay as parameter from my configuration file, instead of hard-wiring it into my task class, like currently...

@Scheduled(fixedDelay=5000)
public void readLog() {
        ...
}

不幸的是,似乎与春节前pression语言手段(EL)@Value返回一个字符串对象,又是不能够被自动装箱为所要求的参数FIXEDDELAY长期价值。

Unfortunately it seems that with the means of the Spring Expression Language (EL) @Value returns a String object which in turn is not able to be auto-boxed to a long value as required by the fixedDelay parameter.

预先感谢你对这个帮助。

Thanks in advance for your help on this.

推荐答案

我猜 @Scheduled 注释是毫无疑问的。因此,也许你的解决方案是使用任务调度<​​/ code> XML配置。让我们考虑这个例子(从<复制的href=\"http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html\">Spring DOC ):

I guess the @Scheduled annotation is out of question. So maybe a solution for you would be to use task-scheduled XML configuration. Let's consider this example (copied from Spring doc):

<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="someObject" method="readLog" 
               fixed-rate="#{YourConfigurationBean.stringValue}"/>
</task:scheduled-tasks>

...或者,如果从字符串投龙没有工作,像这样的:

... or if the cast from String to Long didn't work, something like this would:

<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="someObject" method="readLog"
            fixed-rate="#{T(java.lang.Long).valueOf(YourConfigurationBean.stringValue)}"/>
</task:scheduled-tasks>

同样,我还没有尝试过任何这些设置的,但我希望它可以帮助你一点。

Again, I haven't tried any of these setups, but I hope it might help you a bit.

这篇关于如何参数@Scheduled(FIXEDDELAY)使用Spring 3.0 EX pression语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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