Spring 4 + Spring Batch + Quartz 2.2.x 教程

标签 spring quartz-scheduler spring-batch

几天来我一直在寻找一个简单的 Spring 批处理处理器的调度器 (Quartz) 实现,但没有成功!我手上的所有样本都没有工作或折旧,我的应用程序应该提供设置作业触发时间动态(从数据库中检索)

最佳答案

尝试在 spring-quartz.xml 文件中添加以下代码

<!--testAlerts cron trigger -->
<bean id="testAlertsTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
    <property name="name" value="testAlertsTrigger" />
    <property name="jobDetail" ref="testAlertsJobDetail" />
    <property name="cronExpression" value="0 0 4 * * ?" />
</bean>

<!-- scheduler -->
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="hbnTransactionManager" />
    <property name="triggers">
        <list>
              <ref bean="testAlertsTrigger" />
        </list>
    </property>
    <property name="schedulerContextAsMap">
        <map>
            <entry key="commandDispatcher" value-ref="commandDispatcher" />
        </map>
    </property>
    <property name="autoStartup" value="${QUARTZ.org.quartz.autoStartup}" />
    <property name="overwriteExistingJobs" value="${QUARTZ.org.quartz.overwriteExistingJobs}" />
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.instanceId">${QUARTZ.org.quartz.scheduler.instanceId}</prop>
            <prop key="org.quartz.scheduler.instanceName">${QUARTZ.org.quartz.scheduler.instanceName}</prop>
            <prop key="org.quartz.threadPool.threadCount">${QUARTZ.org.quartz.threadPool.threadCount}</prop>
            <prop key="org.quartz.jobStore.class">${QUARTZ.org.quartz.jobStore.class}</prop>
            <prop key="org.quartz.jobStore.isClustered">${QUARTZ.org.quartz.jobStore.isClustered}</prop>
            <prop key="org.quartz.jobStore.clusterCheckinInterval">${QUARTZ.org.quartz.jobStore.clusterCheckinInterval}</prop>
        </props>
    </property>
</bean>

关于Spring 4 + Spring Batch + Quartz 2.2.x 教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21995345/

相关文章:

java - PersistenceAnnotationBeanPostProcessor 是否会以某种方式影响环境或@PropertySource?

java - quartz : skipping duplicate job fires scheduled with same fire time

java - 使用 @EnableBatchProcessing 指定 JobRepository 隔离级别

java - 动态创建作业的 Spring 批量测试

java - Grails Unresolved 依赖错误

spring - 使用 @RequestMapping 编码到 Spring Controller 方法上的接口(interface)

java - Spring序列化时如何忽略临时对象属性

java - 批处理作业未执行

.net - Quartz.net:预定的代码在部署后不自动工作,在本地工作

java - 如何在 HierarchicalStreamReader 转换器中使用 xml 标签获取 xml 元素的值