spring定时任务的几种配置方法
来源:互联网 发布:c语言的数据类型有哪些 编辑:程序博客网 时间:2024/06/03 17:14
首先在配置文件头部的必须要有:
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd
1、Spring注解配置<task:annotation-driven/>
例子:
spring.xml配置
<context:component-scan base-package="com.hesvit" /><task:annotation-driven/>
执行任务的bean
@Component@Lazy(value=false)public class TaskTest{ @Scheduled(cron=" 0/5 * * * * ?") public void testfun() { System.out.println("每5s执行一次---------飞呀飞呀,我的骄傲放纵"); }}
2、Spring配置文件配置
例子:
spring.xml配置
<context:component-scan base-package="com.hesvit" /><task:scheduled-tasks> <task:scheduled ref="taskTest" method="testfun" cron="0/3 * * * * ?"/> </task:scheduled-tasks>
执行任务的bean
@Component@Lazy(value=false)public class TaskTest{ public void testfun() { System.out.println("每5s执行一次---------飞呀飞呀,我的骄傲放纵"); }}
cron表达式请参考
http://www.cnblogs.com/liuyitian/p/4108391.html
阅读全文
1 0
- spring定时任务的几种配置方法
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- Spring定时任务的几种实现
- IOUtils总结
- SQL Server AlwaysON 同步模式的疑似陷阱
- 微信小程序维护登录态与获取用户信息
- [机器学习]基于spark框架的scala语言MAC环境的安装
- 高等数学
- spring定时任务的几种配置方法
- java中可视化插件windowbuilder在线安装(最新版)
- java的poi技术读取Excel数据到MySQL
- win10下安装Open Jtag驱动
- 计算机常见名词解释
- java写一个堆排序(大顶堆)
- 关于异常nested exception is java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactor
- Android自定义控件(特效一) 点击屏幕,根据所点击的位置绘制圆环
- 微信小程序之获取并解密用户数据(获取openId、unionId)