在原先 Spring 4.0.8 MVC 的基礎下,增加 Spring Quartz 的設定。
Spring Quartz 排程
需要以下 jar
Spring Quartz 設定檔
<bean id="exampleBusinessObject" class="com.tcg.task.MyJob" />
<bean id="exampleBusinessObject2" class="com.tcg.task.MyJob2" />
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="exampleBusinessObject"/>
<property name="targetMethod" value="doIt"/>
</bean>
<bean id="jobDetail2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="exampleBusinessObject2"/>
<property name="targetMethod" value="doIt"/>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<!-- see the example of method invoking job above -->
<property name="jobDetail" ref="jobDetail"/>
<!-- 10 seconds -->
<property name="startDelay" value="10000"/>
<!-- repeat every 50 seconds -->
<property name="repeatInterval" value="50000"/>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail2"/>
<!-- run every morning at 6 AM -->
<property name="cronExpression" value="0 0 6 * * ?"/>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
<ref bean="simpleTrigger"/>
</list>
</property>
</bean>
新增兩個java 程式
package com.tcg.task;
public class MyJob {
public void doIt() {
System.out.println("MyJob..doIt..");
}
}
package com.tcg.task;
public class MyJob2 {
public void doIt() {
System.out.println("MyJob2..doIt..");
}
}
這樣就完成了使用Spring Quartz,兩種排成的設定了。