360SDN.COM

spring3+quartz2配置多个定时任务job.xml

来源:  2013-07-31 16:41:51    评论:0点击:

spring中要配置多个job,只需要在org.springframework.scheduling.quartz.SchedulerFactoryBean部分的list属性中添加需要定时的任务,另外spring3已经提供了对quartz2的封装支持,区别是:

将org.springframework.scheduling.quartz.CronTriggerBean修改org.springframework.scheduling.quartz.CronTriggerFactoryBean

将JobDetailBean修改为JobDetailFactoryBean


<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop
	 http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> 
<!--定时任务1-->
<bean id="job1" class="com.quartzjob.Job1" />
<!--定时任务2-->
<bean id="job2" class="com.quartzjob.Job2" /> 

<bean id="jobDetail_1"
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
   <property name="targetObject">
    <ref bean="job1" />
   </property>
   <property name="targetMethod">
    <value>jobMethod1</value>//执行的方法
   </property>
  <property name="concurrent">
	 <value>false</value>
  </property>
</bean>
<bean id="jobDetail_2"
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
   <property name="targetObject">
    <ref bean="job2" />
   </property>
   <property name="targetMethod">
    <value>jobMethod2</value>
   </property>
  <property name="concurrent">
	 <value>false</value>
  </property>
</bean>

<bean id="cron1"
   class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
   <property name="jobDetail">
    <ref bean="jobDetail_1" />
   </property>
   <property name="cronExpression">
    <!-- 每隔10秒钟触发一次 -->
	 <value>0/10 * * ? * *</value>
   </property>

</bean>
<bean id="cron2"
   class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
   <property name="jobDetail">
    <ref bean="jobDetail_2" />
   </property>
   <property name="cronExpression">
   <!--每小时执行一次-->
    <value>0 0 */1 * * ?</value>
   </property>
</bean>

<bean
   class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
   <property name="triggers">
    <list>
     <ref local="cron1" />
     <ref local="cron2" />
    </list>
   </property>
</bean>

</beans>
为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权