---
title: "spring quartz定时程序"
author: "king520"
date: "2012-10-15T17:02:00Z"
tags: []
slug: "spring-quartz"
draft: false
lastmod: "2012-11-01T17:45:45Z"
id: 1711632
url: "https://king520.iteye.com/blog/1711632"
---

1.配置功能bean

2.定义调用对象及调用方法

```
    <bean id="sendMailJobTask"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject">
            <ref bean="mimeMailService" />
        </property>
        <!-- 调用类中的方法 -->
        <property name="targetMethod">
            <value>sendMailJob</value>
        </property>
    </bean >
```

3.定义触发时间

```
  <bean id="sendMailTrigger"
        class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="sendMailJobTask" />
        </property>
        <!-- cron表达式 -->
        <property name="cronExpression">
            <value>0/5 * * * * ?</value>
        </property>
    </bean>
```

4.加入到定时器队列中。

```
	<bean id="startQuertz" lazy-init="false" autowire="no"  class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
	        <property name="triggers">
	            <list>
	                <ref bean="sendMailTrigger" />
	             </list>
	        </property>
	</bean>
```