现在的位置: 首页 > 综合 > 正文

Quartz框架简单使用

2017年04月14日 ⁄ 综合 ⁄ 共 2667字 ⁄ 字号 评论关闭

从此处学习到的配置方法: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>

抱歉!评论已关闭.