1、在xml配置文件applicationContext.xml的命名空间增加如下信息:
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.3.xsd
2、在上述文件中启动定时任务开关,增加如下配置即可
<task:annotation-driven />
3、进行具体的定时任务配置
<task:scheduled-tasks>
<!-- 这里表示的是每隔五秒执行一次 -->
<task:scheduled ref="myTask" method="show" cron="*/5 * * * * ?" />
<task:scheduled ref="myTask" method="print" cron="*/10 * * * * ?"/>
</task:scheduled-tasks>
或者在代码里利用注解进行配置
@Scheduled(cron = "0 0 1 * * *")