項目中真實遇到過的配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-4.0.xsd">
<!-- 定義任務bean --><bean name="paymentOrderJobDetail"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<!-- 指定具體的job類 -->
<property name="jobClass" value="com.taobao.store.order.job.PaymentOrderJob" />
<!-- 指定job的名稱 -->
<property name="name" value="paymentOrder" />
<!-- 指定job的分組 -->
<property name="group" value="Order" />
<!-- 必須設置爲true,如果爲false,當沒有活動的觸發器與之關聯時會在調度器中刪除該任務 --><property name="durability" value="true"/>
<!-- 指定spring容器的key,如果不設定在job中的jobmap中是獲取不到spring容器的 --><property name="applicationContextJobDataKey" value="applicationContext"/>
</bean><!-- 定義觸發器 -->
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"><property name="jobDetail" ref="paymentOrderJobDetail" />
<!-- 每一分鐘執行一次 --><property name="cronExpression" value="0 0/1 * * * ?" />
<!-- 補充執行的時間問題:
一個cronExpression表達式有至少6個(也可能是7個)由空格分隔的時間元素。從左至右,這些元素的定義如下:
1.秒(0–59)
2.分鐘(0–59)
3.小時(0–23)
4.月份中的日期(1–31)
5.月份(1–12或JAN–DEC)
6.星期中的日期(1–7或SUN–SAT)
7.年份(1970–2099)
案例:
0
0 10,14,16 * * ?
每天上午10點,下午2點和下午4點
0 0,15,30,45 * 1-10 * ?
每月前10天每隔15分鐘
30 0 0 1 1 ? 2012
在2012年1月1日午夜過30秒時
0 0 8-5 ? * MON-FRI
每個工作日的工作時間
各個時間可用值如下:
秒0-59 , - * /
分0-59 , - * /
小時0-23 , - * /
日1-31 , - * ? / L W C
月1-12 or JAN-DEC , - * /
周幾1-7 or SUN-SAT , - * ? / L C #
年(可選字段) empty, 1970-2099 , - * /
-->
</bean><!-- 定義調度器 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers">
<list><ref bean="cronTrigger" />
</list>
</property>
</bean>
</beans>