- <!-- 任務目標 -->
- <bean id="eggsJob" class="com.ucc.service.EggsJob">
- <property name="eggService" ref="eggsService"></property>
- </bean>
-
- <!-- 包裝“任務目標”為quartz的子類,並設定需要執行的方法 -->
- <bean id="jobDetailBean" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <property name="targetObject" ref="eggsJob"></property>
- <property name="targetMethod" value="excute"></property>
- </bean>
-
- <!-- 制訂任務周期,並指定周期執行目標 -->
- <bean id="cronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail" ref="jobDetailBean"></property>
- <property name="cronExpression" value="0 0 0 24-31,1-3 12,1 ?"></property>
- </bean>
-
- <!-- 制訂任務列表 -->
- <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list>
- <ref bean="cronTriggerBean"/>
- </list>
- </property>
- </bean>
這個定時器只需要編寫一個EggsJob類,且無須實現與繼承任何類;簡單實用