如何配置 JBoss/Quartz 来运行 Spring 作业?
我是 JBoss 的新手,已经使用 tomcat 多年了。我有一个 Spring 3.0.x 应用程序,我需要在其中定期运行一项作业。过去,我只是将作业类创建为常规 POJO,然后将作业/触发器创建为 Spring 的 CronTriggerBean,并传递 MethodInvokingJobDetailFactoryBean 作为我的 jobDetail。
例如:
<bean id="session.manage.UserSessionPurgeAction.trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="cronExpression" value="0 */5 * * * ? *" />
<property name="jobDetail">
<bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="name"><idref bean="session.manage.UserSessionPurgeAction" /></property>
<property name="group" value="cleanup" />
<property name="targetObject" ref="session.manage.UserSessionPurgeAction" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
</property>
</bean>
在这个新项目中,系统架构师要求在 JBoss 6 下运行 Spring 应用程序。我知道 JBoss 内置了一个quartz调度程序,所以我不确定如何打包/声明我的作业,以便它使用 JBoss ' 调度程序,而不是像我过去所做的那样将其构建到应用程序中。
我在网上搜索过,但似乎找不到我需要的必要的胶水信息。我知道 javax.ejb 中有一个 @Schedule 注释,但这就是我需要添加到我的方法中的所有内容吗?我认为/期望我需要在某个地方进行额外的配置,但不确定在哪里。
有人能指出我正确的方向吗?
谢谢,
埃里克
I'm new to JBoss, having been using tomcat for years. I have a Spring 3.0.x application in which I need to run a job on a regular basis. In the past, I would simply create my job class as a regular POJO, and then create my job/trigger as Spring's CronTriggerBean passing a MethodInvokingJobDetailFactoryBean as my jobDetail.
Ex:
<bean id="session.manage.UserSessionPurgeAction.trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="cronExpression" value="0 */5 * * * ? *" />
<property name="jobDetail">
<bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="name"><idref bean="session.manage.UserSessionPurgeAction" /></property>
<property name="group" value="cleanup" />
<property name="targetObject" ref="session.manage.UserSessionPurgeAction" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
</property>
</bean>
On this new project, the system architect has called for running the Spring application under JBoss 6. I know that JBoss has a quartz scheduler built in, so I am not sure how to package/declare my job such that it is using JBoss' scheduler as opposed to building it into the app as I have done in the past.
I've searched online, but cannot seem to find the necessary glue information that I need. I know that there is a @Schedule annotation in javax.ejb but is that all I need to add to my method? I would think/expect that I need additional configuration somewhere, but not sure where.
Can anyone point me in the right direction please?
Thanks,
Eric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实想使用 jboss,我会尝试将传递给 SchedulerFactoryBean 的 SchedulerName 属性与捆绑的调度程序之一进行匹配。捆绑的调度程序可以通过 JNDI 检索,我认为它的 jndi 名称为“Quartz”。
看一下 org.springframework.scheduling.quartz.SchedulerFactoryBean#createScheduler,它首先尝试在静态 SchedulerRepository 中查找调度程序。
If you really want to use the jboss one, I would try matching the schedulerName property passed to SchedulerFactoryBean with one of the bundled scheduler. The bundled scheduler can be retrieved via JNDI, it's under jndi name "Quartz" I think.
Have a look at org.springframework.scheduling.quartz.SchedulerFactoryBean#createScheduler, it tries to look up the scheduler in static SchedulerRepository first.