Spring通过注解使用定时器(已经验证)
来源:互联网 发布:知行理工闪退 编辑:程序博客网 时间:2024/05/21 06:25
先需要在springMVC的配置文件中,配置定时器的扫描注解
1
2
<!-- 定时器开关 开始-->
<
task:annotation-driven
/>
定时器的实现代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package
com.test.control.base;
import
org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component;
@Component
public
class
SpringTimerTest {
/**
* 启动时执行一次,之后每隔3秒执行一次
*/
@Scheduled
(fixedRate =
1000
*
3
)
public
void
print() {
System.out.println(
"timer running..."
);
}
/**
* 定时启动。每天凌晨 16:19 执行一次
*/
@Scheduled
(cron =
"0 19 16 * * *"
)
public
void
show() {
System.out.println(
"定时器启动..."
);
}
}
最后写个main方法测试下
1
2
3
public
static
void
main(String[] args) {
ApplicationContext ctx =
new
ClassPathXmlApplicationContext(
"springmvcContext.xml"
);
}
0 0
- Spring通过注解使用定时器(已经验证)
- spring task(定时器) 使用注解方式
- Spring注解下使用定时器
- java spring定时器(注解)
- Spring 定时器配置 基于注解 (使用 Spring4)
- spring 使用注解启动定时器不执行
- Spring定时器的使用(注解+xml形式)
- 使用spring定时器注解实现定时任务
- spring中使用注解启动定时器
- 定时器(Spring定时器)使用
- spring 注解配置定时器
- Spring注解定时器@Scheduled
- spring注解定时器
- Spring 注解 定时器
- spring定时器基于注解
- Spring定时器-注解
- 使用注解和自定义验证实现Spring MVC表单验证(翻译)
- spring Security4 和 oauth2整合 注解+xml混合使用(验证码等额外数据验证)
- 自有域名、IIS7,搭建SMTP邮件服务器
- 【黑马程序员】第三篇_关于I/O的总结
- printf 使用
- Android Studio为APP签名,提取签名的SHA1/MD5编码
- 从一个盒子模型说起
- Spring通过注解使用定时器(已经验证)
- 秒杀技术的实现以及相应防作弊策略介绍
- android animation
- leetcode First Bad Version
- c++ 顺序存储和链表存储 栈的实现代码
- ExtJs—Grid多选框中勾选与单击事件的冲突
- 问题-ListView 使用的时候,已经遇到的问题;
- Intel Edison C++ 开发之I2C-使用MRAA库进行C/C++开发
- 2016 免费申请邓白氏码的步骤