quartz + spring 配置示例

<!-- 配置job定时任务类 -->
    <bean id="triggerCalculateLecturerProfitJob" class="com.itzixi.quartz.job.CalculateLecturerProfitJob"></bean>
    
    <!-- 配置jobDetail -->
    <bean id="triggerCalculateLecturerProfitJobMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject">
            <ref bean="triggerCalculateLecturerProfitJob"/>
        </property>
        <!-- 要执行triggerCalculateLecturerProfitJob的方法的名称 -->
        <property name="targetMethod">
            <value>execute</value>
        </property>
    </bean>
    
    <!-- 配置定时任务触发器trigger -->
    <bean id="triggerCalculateLecturerProfitJobFactoryBean" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="triggerCalculateLecturerProfitJobMethod"></property>
        <!-- 用于测试,每分钟跑一次 -->
<!--         <property name="cronExpression" value="0 0/1 * * * ?"></property> -->
        <!-- 每晚凌晨1点跑 -->
        <property name="cronExpression" value="0 0 1 * * ? *"></property>
    </bean>

    <!-- 配置调度工厂 -->
    <bean id="springJobSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="triggerCalculateLecturerProfitJobFactoryBean"/>
            </list>
        </property>
    </bean>

 

posted @ 2017-06-16 11:58  风间影月  阅读(320)  评论(0编辑  收藏  举报