Spring定时器

两个类:
public class Test1 extends QuartzJobBean{
  public void handle(){
    System.out.println("Test1");
  }
}

public class Test2 extends QuartzJobBean{
  public void handle(){
    System.out.println("Test2");
  }
}


applicationContext.xml配置
<bean id="test1" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass">
    <value>test.shedule.Test1</value>
  </property>
</bean>
<bean id="test2" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass">
    <value>test.shedule.Test2</value>
  </property>
</bean>
<!-- 简单触发器 -->
<bean id="helloTest1" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
  <property name="jobDetail">
    <ref bean="test1"/>
  </property>
  <property name="startDelay">
    <value>1000</value>
  </property>
  <property name="repeatInterval">
    <value>3000</value>
  </property>
</bean>
<!-- 复杂触发器 -->
<bean id="helloTest2" class="org.springframework.scheduling.quartz.CronTriggerBean">
  <property name="jobDetail">
    <ref bean="test2" />
  </property>
  <!--每天下午14:18分触发-->
  <property name="cronExpression">
    <value>00 18 14 * * ?</value>
  </property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  <property name="triggers">
    <list>
      <ref local="helloTest1" />
      <ref local="helloTest2" />
    </list>
  </property>
</bean>


PS: 需要jta.jar和quartz-all-1.6.0.jar支持, commons-collections-3.1.jar
如果导入commons-collections-3.1.jar仍然报错,可以把commons-collections-3.1.jar放在jdk\jre\lib\ext\下面,即可解决问题

你可能感兴趣的:(spring)