要使用定时任务,需要将quartz-1.5.2.jar加入lib,没有的话可以从下面地址下载:
有了这个再做个配置文件appctx-quartz.xml:
被调用的类如下:
package com.ufo.unknown.quartz;public class Test{ public void print(){ System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); }}
然后在周六的21点17分0秒,Test类的print函数就被调用了,控制台输出如下:
DEBUG (JobRunShell.java:202) - Calling execute on job DEFAULT.jobTestDEBUG (CachedIntrospectionResults.java:222) - Getting BeanInfo for class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob]DEBUG (CachedIntrospectionResults.java:238) - Caching PropertyDescriptors for class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob]DEBUG (CachedIntrospectionResults.java:250) - Found bean property 'class' of type [java.lang.Class]DEBUG (CachedIntrospectionResults.java:250) - Found bean property 'methodInvoker' of type [org.springframework.util.MethodInvoker]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>