首页 > 代码库 > quartz spring 配置定时触发

quartz spring 配置定时触发

 1 <bean id="kintaiAdditionalCreating" class="com.kng.timevalue.kintaiAdditional.KintaiAdditionalCreating" /> 2 第一行是<!-- 要调用的工作类 -->
    第3-11行<!-- 指定任务Bean的实现类 --><!-- 为任务Bean注入属性 --> 
3 <bean name="kintaiJob" class="org.springframework.scheduling.quartz.JobDetailBean"> 4 <property name="jobClass" value="com.kng.timevalue.kintaiAdditional.KintaiJob" /> 5 <!-- 指定任务Bean的实现类 --> 6 <property name="jobDataAsMap"><!-- 为任务Bean注入属性 -->  7 <map> 8 <entry key="kintaiCreating" value-ref="kintaiAdditionalCreating" /> 9 </map>10 </property>11 </bean>12 第13-16行<!-- 定义触发时间 -->13 <bean id="kintaiCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">14 <property name="jobDetail" ref="kintaiJob" />15 <property name="cronExpression" value="0 02 17 * * ? *" />16 </bean>17 第18-30行定义管理的18 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">19 <property name="jobDetails">20 <list>21 <ref bean="kintaiJob" />22 </list>23 </property>24 25 <property name="triggers">26 <list>27 <ref bean="kintaiCronTrigger" />28 </list>29 </property>30 </bean>
 1 public class KintaiJob extends QuartzJobBean { 2  3     @Autowired 4     private KintaiAdditionalCreating kintaiCreating; 5  6      7  8     /** 9      * @param kintaiCreating the kintaiCreating to set10      */11     public void setKintaiCreating(KintaiAdditionalCreating kintaiCreating) {12         this.kintaiCreating = kintaiCreating;13     }14 15 16 17     protected void executeInternal(JobExecutionContext context)18             throws JobExecutionException {19         kintaiCreating.addKintai();20     }21 22 }

第二段代码是编写Job类PunchJob该类必须继承QuartzJobBean)

这个类KintaiAdditionalCreating 里写要实现的逻辑

quartz spring 配置定时触发