1. 程式人生 > >spring @scheduled 定時任務註解使用

spring @scheduled 定時任務註解使用

Spring @scheduled 用法:
定時任務註解

需要新增的如下圖所示:

一、新增配置

1.
xmlns:task="http://www.springframework.org/schema/task"
2.
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd
3.
<!-- 定時器開關 開始 -->
<task:annotation-driven />
4.
<context:component-scan base-package="包名"/>   

二、開始使用

@Scheduled(cron = "0/5 * * * * ?")  每5秒執行一次
@Scheduled(cron = "0 0 */1 * * ?")  每隔1小時執行一次