Spring定时任务的简单配置

版权声明: https://blog.csdn.net/Dongguabai/article/details/82705007

在Spring的配置文件中加上:

xmlns:task="http://www.springframework.org/schema/task"

http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task-3.0.xsd

配置好包扫描路径后,接下来可以在Spring组件中使用@Scheduled注解:

关于cron表达式可以参看:http://www.pdtools.net/tools/becron.jsp#cron

表示式 说明
"0 0 12 * * ? " 每天12点运行
"0 15 10 ? * *" 每天10:15运行
"0 15 10 * * ?" 每天10:15运行
"0 15 10 * * ? *" 每天10:15运行
"0 15 10 * * ? 2008" 在2008年的每天10:15运行
"0 * 14 * * ?" 每天14点到15点之间每分钟运行一次,开始于14:00,结束于14:59。
"0 0/5 14 * * ?" 每天14点到15点每5分钟运行一次,开始于14:00,结束于14:55。
"0 0/5 14,18 * * ?" 每天14点到15点每5分钟运行一次,此外每天18点到19点每5钟也运行一次。
"0 0-5 14 * * ?" 每天14:00点到14:05,每分钟运行一次。
"0 10,44 14 ? 3 WED" 3月每周三的14:10分到14:44,每分钟运行一次。
"0 15 10 ? * MON-FRI" 每周一,二,三,四,五的10:15分运行。
"0 15 10 15 * ?" 每月15日10:15分运行。
"0 15 10 L * ?" 每月最后一天10:15分运行。
"0 15 10 ? * 6L" 每月最后一个星期五10:15分运行。
"0 15 10 ? * 6L 2007-2009" 在2007,2008,2009年每个月的最后一个星期五的10:15分运行。
"0 15 10 ? * 6#3" 每月第三个星期五的10:15分运行。

猜你喜欢

转载自blog.csdn.net/Dongguabai/article/details/82705007
今日推荐