步骤一:找到web.xml 添加如下
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<context:component-scan base-package="com.weirdo.timedTask"/>
<task:scheduler id="scheduler" pool-size="10"/>
<task:annotation-driven scheduler="scheduler"/>
步骤二:创建定时任务
@Component
public class MyTask {
@Scheduled(cron = "*/5 * * * * *")
public void task1() {
System.out.println("定时任务");
}
}
/*
*
* 秒 分 时 日 月 年
* */5 * * * * *
*
*/
重启项目 就可以看到 每隔五秒打印一次。