首先我们编写调度服务,继承java.util.TimerTask













配置文件:


























测试代码:




























运行结果:
2007-6-5 23:16:24 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@109a4c: display name [org.springframework.context.support.FileSystemXmlApplicationContext@109a4c]; startup date [Tue Jun 05 23:16:24 CST 2007]; root of context hierarchy
2007-6-5 23:16:24 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from file [E:/项目/SpringInActionStudy/TimerTest/hello.xml]
2007-6-5 23:16:24 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@109a4c]: org.springframework.beans.factory.support.DefaultListableBeanFactory@cd2c3c
2007-6-5 23:16:24 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@cd2c3c: defining beans [reportTask,scheduledReportTask,start]; root of factory hierarchy
2007-6-5 23:16:24 org.springframework.scheduling.timer.TimerFactoryBean afterPropertiesSet
信息: Initializing Timer
25
26
27
可以看到,每隔一秒就打印当前时间的秒数