---
title: "spring多个定时任务"
author: "feohoo"
date: "2011-01-22T17:30:39Z"
tags: []
categories: ["企业架构"]
slug: "spring"
draft: false
lastmod: "2011-01-22T17:30:39Z"
id: 891560
url: "https://feohoo.iteye.com/blog/891560"
---

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)   
[http://www.springframework.org/schema/beans/spring-beans-2.5.xsd](http://www.springframework.org/schema/beans/spring-beans-2.5.xsd)"  
default-lazy-init="false"&gt;

&lt;bean id="job1" class="com.job.Job1" /&gt;//任务1  
&lt;bean id="job2" class="com.job.Job2" /&gt;//任务2

&lt;bean id="jobDetail\_1"  
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;  
   &lt;property name="targetObject"&gt;  
    &lt;ref bean="job1" /&gt;  
   &lt;/property&gt;  
   &lt;property name="targetMethod"&gt;  
    &lt;value&gt;jobMethod1&lt;/value&gt;//执行的方法  
   &lt;/property&gt;  
&lt;/bean&gt;  
&lt;bean id="jobDetail\_2"  
   class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;  
   &lt;property name="targetObject"&gt;  
    &lt;ref bean="job2" /&gt;  
   &lt;/property&gt;  
   &lt;property name="targetMethod"&gt;  
    &lt;value&gt;jobMethod2&lt;/value&gt;  
   &lt;/property&gt;  
&lt;/bean&gt;

&lt;bean id="cronTrigger\_1"  
   class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;  
   &lt;property name="jobDetail"&gt;  
    &lt;ref bean="jobDetail\_1" /&gt;  
   &lt;/property&gt;  
   &lt;property name="cronExpression"&gt;  
    &lt;value&gt;0 0 0 * * ?&lt;/value&gt;//每天凌晨12点执行一次  
   &lt;/property&gt;

&lt;/bean&gt;  
&lt;bean id="cronTrigger\_2"  
   class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;  
   &lt;property name="jobDetail"&gt;  
    &lt;ref bean="jobDetail\_2" /&gt;  
   &lt;/property&gt;  
   &lt;property name="cronExpression"&gt;  
    &lt;value&gt;0 0 \*/1 * * ?&lt;/value&gt;//每小时执行一次  
   &lt;/property&gt;  
&lt;/bean&gt;

&lt;bean  
   class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;  
   &lt;property name="triggers"&gt;  
    &lt;list&gt;  
     &lt;ref local="cronTrigger\_1" /&gt;  
     &lt;ref local="cronTrigger\_2" /&gt;  
    &lt;/list&gt;  
   &lt;/property&gt;  
&lt;/bean&gt;

&lt;/beans&gt;

&lt;!--EndFragment--&gt;