实体类 extends QuartzJobBean
/** * * @author Frank *@date 2014 02-16 */ public class MyJobServiceImple extends QuartzJobBean { private SmartMenuScheduleService smartMenuScheduleService; @Override protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException { /** * 调用同步方法 */ this.getSmartMenuScheduleService().sendMenuSchedule(); } public SmartMenuScheduleService getSmartMenuScheduleService() { return smartMenuScheduleService; } public void setSmartMenuScheduleService(SmartMenuScheduleService smartMenuScheduleService) { this.smartMenuScheduleService = smartMenuScheduleService; } }
<bean id="myJob" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass" value="com.hestia.mosa.menu.service.MyJobServiceImple" /> <property name="jobDataAsMap"> <map> <entry key="smartMenuScheduleService"> <ref bean="smartMenuScheduleService" /> </entry> </map> </property> </bean> <!-- 同步触发器 --> <bean id="groupCustomerTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="myJob" /> <!-- Cron表达式:每天凌晨1点执行一次 --> <property name="cronExpression"> <value>0 0 1 * * ?</value> </property> </bean> <!-- 任务调度器 如果将lazy-init=‘false‘那么容器启动就会执行调度程序 --> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="transactionManager" ref="transactionManager" /> <property name="triggers"> <list> <ref bean="groupCustomerTrigger" /> </list> </property> <property name="quartzProperties"> <map> <entry key="org.quartz.threadPool.threadCount" value="1" /> </map> </property> </bean>
原文:http://blog.csdn.net/pengchengmm/article/details/19290215