前端之家收集整理的这篇文章主要介绍了
Springmvc配置定时任务注解开发,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
502_0@1、
添加命名空间和xsd约束
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
@H_
502_0@2、在 application.xml
文件中开启注解
<task:annotation-driven />
@H_
502_0@3、配置扫描任务扫描包
<context:component-scan base-package="com.task" />
@H_
502_0@4、demo
@Component
public class AutoScanTask {
@Scheduled(cron = "0/5 * * * * ? ") // 间隔5秒执行
public void autoScan() {
System.out.println("定时器执行");
}
}