spring.xml
<bean id="businessObjectExample"
class="org.chfzhb.BusinessObject" />
<bean id="myjobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="businessObjectExample" />
<property name="targetMethod" value="doIt" />
<property name="concurrent" value="false" />
</bean>
<!-- 注意:默认情况下,jobs在并行的方式下运行 -->
<!-- 使用SimpleTriggerBean, CronTriggerBean来包装任务 -->
<bean id="simpleTrigger"
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="myjobDetail" />
<!-- 延时1m 执行任务 -->
<property name="startDelay" value="10000" />
<!-- 任务执行周期 3m -->
<property name="repeatInterval" value="5000000" />
</bean>
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="myjobDetail" />
<!-- 每天早上6点钟运行 -->
<property name="cronExpression" value="0 26 23 * * ?" />
</bean>
<!-- 现在我们创建了两个triggers,其中一个开始延迟10秒以后每50秒运行一次,另一个每天早上6点钟运行。我们需要创建一个SchedulerFactoryBean来最终实现上述的一切
-->
<bean id="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger"/>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
BusinessObject.java
package org.chfzhb;
import java.util.Date;
public class BusinessObject {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void doIt() {
System.out.println("现在时间: " + new Date());
}
}
测试成功。。