Quartz框架簡單使用

從此處學習到的配置方法:http://www.oschina.net/question/200745_62107


最重要的一個配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

	<!--    Quartz config bean -->
   <bean id="examTipAndDeleteQuartz" class="com.onnet.utils.schedule.ExamTipAndDeleteQuartz">
        <property name="mailService" ref="mailServiceImpl" />
        <property name="examService" ref="examServiceImpl" />
        <property name="systemTimeService" ref="systemTimeServiceImpl" />
    </bean>
   <bean id="checkAccountQuartz" class="com.onnet.utils.schedule.CheckAccountQuartz">
        <property name="orderService" ref="orderServiceImpl" />
    </bean>

    <!-- bean觸發方法配置 -->
    <bean id="methodInvokeBean" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="examTipAndDeleteQuartz" />
        <property name="targetMethod" value="tipAndDelete" />
        <property name="concurrent" value="false" /><!-- 併發,默認值是true,不存在併發一說 -->
    </bean>
    <bean id="methodInvokeBean2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="checkAccountQuartz" />
        <property name="targetMethod" value="checkAccountByTime" />
        <property name="concurrent" value="false" /><!-- 併發,默認值是true,不存在併發一說 -->
    </bean>

    <!-- 配置執行時間表達式  -->
    <bean id="cronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="methodInvokeBean"></property>
        <property name="cronExpression" value="0 0 1 * * ?" /><!-- 每天凌晨2點 -->
    </bean>
    <bean id="cronTriggerBean2" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="methodInvokeBean2"></property>
        <property name="cronExpression" value="0 0 3 * * ?" /><!-- 每天凌晨3點 -->
    </bean>

    <!-- 配置調度器 -->
    <bean id="scheduledFactoryBean"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="cronTriggerBean" />
                <ref bean="cronTriggerBean2" />
            </list>
        </property>
    </bean>

</beans>




發佈了116 篇原創文章 · 獲贊 15 · 訪問量 35萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章