很简单,一共需要定义三个bean 需要注意的是每个bean的类型

  1. 业务bean(就是我们每次调度需要做的工作)

 

<bean id="quantzjobBean" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass">
            <!-- 实现了org.springframework.scheduling.quartz.QuartzJobBean的JobBean -->
            <value>com.jiaoyiping.study.quartz.SendEmailJob</value>
        </property>
        <!-- 调用业务逻辑 -->
        <!--
        <property name="jobDataAsMap">
            <map>
                <entry key="biz">
                    <ref bean="users"/>
                </entry>
            </map>
        </property>
        -->
    </bean>

 

2.触发任务的bean(在这里可以指定在什么条件下触发,执行多少次等等)

  <!-- 触发任务条件 -->
    <bean id="simpletriggerbean" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <property name="jobDetail" ref="quantzjobBean"></property>
        <!-- 延迟一分钟启动 -->
        <property name="startDelay">
            <value>60000</value>
        </property>
        <!-- 每隔1分钟调用一次 -->
        <property name="repeatInterval">
            <value>60000</value>
        </property>
        <!-- 重复执行10次 -->
        <property name="repeatCount">
            <value>10</value>
        </property>

    </bean>

 

 

3.启动调度的bean(注入这个bean之后spring会自动地按照bean中的配置执行相应的内容)

<bean id="startQuartz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="simpletriggerbean"/>
            </list>
        </property>
    </bean>

posted on 2013-09-01 19:37  梦中彩虹  阅读(338)  评论(0编辑  收藏  举报