如何在 Spring 3 中配置自定义触发器?
我需要配置一个调度算法,该算法超出了 Spring 内置调度的能力(基本上“每 5 分钟一次,但仅在 4:00h 到 16:00h 之间”)。看来实现 org.springframework.scheduling.Trigger 接口是可行的方法,这看起来很简单。
我无法弄清楚的部分似乎没有在 文档是:它如何与 XML 配置混合?似乎没有任何方法可以在任务命名空间的元素中指定自定义触发器 bean(除了 Quartz 示例)。
如何在 Spring 3 应用程序中使用自定义触发器?理想情况下使用 Bean XML 配置。
I need to configure a scheduling algorithm that is beyond the capabilities of Spring's in-build scheduling (basically "every 5 minutes, but only between 4:00h and 16:00h"). It seems that implementing the org.springframework.scheduling.Trigger interface is the way to go, which seems simple enough.
The part I can't figure out and that doesn't seem to be answered in the documentation is: how does this mix with the XML configuration? There doesn't seem to be any way of specifying a custom trigger bean in the elements of the task namespace (apart from the Quartz example).
How do I use a custom trigger in a Spring 3 application? Ideally using the Bean XML configuration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看 DurationTrigger 我一年前写的。
以下是如何使用此触发器安排此类任务:
或者,您可以使用 CronTrigger / cron 表达式:
查看此 JIRA 以及 Spring Integration 文章
编辑< /strong>:
根据 JIRA 讨论,您可以使用 Spring Integration 配置上面的
DurationTrigger
或任何其他自定义触发器:在项目中使用 Spring Integration 非常简单,即使你没有计划 到。您可以尽可能少地使用上述调度部分,也可以尽可能依赖 Spring Integration 提供的许多其他企业集成模式。
Take a look at DurationTrigger I wrote a year ago.
Here is how you would schedule such a task with this trigger:
Alternatively, you can use a CronTrigger / cron expression:
Check out this JIRA as well as this Spring Integration article
EDIT:
From the JIRA discussion, you can configure the
DurationTrigger
above, or any other custom trigger for that matter, using Spring Integration:It is quite simple to use Spring Integration in your project, even if you did not plan to. You can use as little as the above scheduling piece, or as much as relying on many other Enterprise Integration patterns that Spring Integration has available.
看来在 Spring 3.0 中使用 XML 来配置除两个标准触发器之外的任何触发器都是不可能的。不过,它已作为新功能添加到 3.1M2 版本中: https://jira.springsource .org/browse/SPR-8205
感谢 Mark Fisher 的指出这一点。
It seems using XML to configure any but the two standard triggers is not possible in Spring 3.0. It has been added as a new feature in the 3.1M2 release, though: https://jira.springsource.org/browse/SPR-8205
Thanks to Mark Fisher for pointing this out.