- 第一步:配置spring.xml
- <beans
-
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd">
- <context:annotation-config/>
- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
- <task:annotation-driven/>
- <!--扫描的是com.crm.web这样的包下的内容-->
- <context:component-scan base-package="com.crm.web" />
- 第二步:接口和实现
- package com.crm.web;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- @Component
- public class MyTask {
- @Scheduled(cron="0 0 1 * * ?") //每天1点触发
- // @Scheduled(cron="0/60 * * * * ? ") //间隔60秒执行
- public void taskCycle(){
- System.out.println("呵呵");
- }
- cron的取值参考:
- /**
- 秒 0-59 , - * /
- 分 0-59 , - * /
- 小时 0-23 , - * /
- 日期 1-31 , - * ? / L W C
- 月份 1-12 或者 JAN-DEC , - * /
- 星期 1-7 或者 SUN-SAT , - * ? / L C #
- 年(可选)留空, 1970-2099 , - * /
- 表达式意义
- "0 0 12 * * ?" 每天中午12点触发
- "0 15 10 ? * *" 每天上午10:15触发
- "0 15 10 * * ?" 每天上午10:15触发
- "0 15 10 * * ? *" 每天上午10:15触发
- "0 15 10 * * ? 2005" 2005年的每天上午10:15触发
- "0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发
- "0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发
- "0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
- "0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发
- "0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2: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 2002-2005" 2002年至2005年的每月的最后一个星期五上午10:15触发
- "0 15 10 ? * 6#3" 每月的第三个星期五上午10:15触发
- * **/
相关推荐
使用spring @Scheduled注解执行定时任务
本文将详细探讨Spring Boot中@Scheduled注解的使用,包括其原理、实现流程、步骤和代码示例。通过本文,读者将能够了解如何在Spring Boot应用中轻松创建和管理定时任务。 # @Scheduled注解简介 在Spring框架中,@...
在不停服务的情况下,动态修改Spring定时任务的执行周期,即动态修改定时任务的cron参数。
spring boot @scheduled注解 cron 表达式实现计划任务调度。
Spring的任务调度@Scheduled注解——task:scheduler和task:executor的解析,做了一些测试说明了各个参数的作用
主要介绍了spring-boot通过@Scheduled配置定时任务,文中还给大家介绍了springboot 定时任务@Scheduled注解的方法,需要的朋友可以参考下
1.在Spring Boot中,你可以使用@Scheduled注解来创建定时任务。将@Scheduled注解与方法一起使用,指定任务执行的时间表达式。 2.使用Spring的TaskScheduler: Spring提供了TaskScheduler接口和相关实现,用于任务...
主要介绍了spring 定时任务@Scheduled的相关资料,文中通过示例代码介绍的很详细,相信对大家的理解和学习具有一定的参考借鉴价值,有需要的朋友们下面来一起看看吧。
本篇文章中主要介绍了Spring Boot中使用@Scheduled创建定时任务,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
本篇文章主要介绍了详解在Spring3中使用注解(@Scheduled)创建计划任务,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
一、基于@Scheduled注解的方式 1.1 cron 1.1.1 定时任务的方法在启动类里面 1.1.2 定时任务的方法在启动类之外 1.2 fixedDelay 1.3 fixedRate 1.4 initialDelay 一点五 cron解释 结构 取值范围 常例 二、基于...
本代码是个demo,展示spring定时任务的三种实现方式:xml配置实现,注解实现及动态定时任务实现。
说明:@Scheduled 注解用于标注这个方法是一个定时任务的方法,有多种配置可选。cron支持cron表达式,指定任务在特定时间执行;fixedRate以特定频率执行任务;fixedRateString以string的形式配置执行频率。
Springmvc java注解设置定时任务实例,利用 ScheduledExecutorService 接口实现
- chapter4-1-1:[使用@Scheduled创建定时任务](http://blog.didispace.com/springbootscheduled/) - chapter4-1-2:[使用@Async实现异步调用](http://blog.didispace.com/springbootasync/) #### 日志管理 - ...
chapter4-1-1:使用@Scheduled创建定时任务 chapter4-1-2:使用@Async实现异步调用 chapter4-1-3:使用@Async实现异步调用:自定义线程池 chapter4-1-4:使用@Async实现异步调用:资源优雅关闭 chapter4-1-5:使用@...
5.添加定时任务:不再使用作业自动调度框架Quartz实现作业调度,使用spring框架自带的调度器进行作业调度,简化了配置。@Scheduled是单线程的,每次最多只有一个作业在运行,如果调度时间到了作业还没执行完,就会...
SpringBoot项目,定时扫表功能(Spring的Scheduled注解方式实现),maven工程
spring task定时任务的demo,基于配置和基于注解两种方法实现