spring多个定时任务job.xml配置

时间:2022-07-16 07:50:36

spring多个定时任务job.xml配置

Posted on 2010-07-07 23:24 chinaifne 阅读(2495) 评论(0)  编辑 收藏

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-lazy-init="false">

 

<bean id="job1" class="com.job.Job1" />//任务1
<bean id="job2" class="com.job.Job2" />//任务2

<bean id="jobDetail_1"
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
   <property name="targetObject">
    <ref bean="job1" />
   </property>
   <property name="targetMethod">
    <value>jobMethod1</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>
</bean>

<bean id="cronTrigger_1"
   class="org.springframework.scheduling.quartz.CronTriggerBean">
   <property name="jobDetail">
    <ref bean="jobDetail_1" />
   </property>
   <property name="cronExpression">
    <value>0 0 0 * * ?</value>//每天凌晨12点执行一次
   </property>

</bean>
<bean id="cronTrigger_2"
   class="org.springframework.scheduling.quartz.CronTriggerBean">
   <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="cronTrigger_1" />
     <ref local="cronTrigger_2" />
    </list>
   </property>
</bean>

</beans>