spring中quartz应用


在applicationContext.xml中的相关设置,如下实例:

1.定义一个Service
  <bean id="recipesService"
class="cn.dinner.service.impl.RecipesServiceImpl">
<property name="dinnerRecipesDao">
<ref bean="DinnerRecipesDAO" />
</property>
  </bean>

2. 指明需要自动运行的任务
  <bean id="methodInvokingJobDetail2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="recipesService" />
</property>
<property name="targetMethod"> <!-- 指明具体方法 -->
<value>copyRecipes</value>
</property>
</bean>

3. 定义自动任务执行周期
   <bean id="cronTrigger1"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="methodInvokingJobDetail2" />
</property>
<property name="cronExpression"><!--每星期天23:59:59 -->
    <value>59 59 23 ? * 1</value>
</property>
</bean>

4. 注册到quartz中执行
<bean
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="cronTrigger1" />
</list>
</property>
</bean>

你可能感兴趣的:(spring,xml,quartz)