首先在xml配置文件头中添加以下几行:
 
 
在xml中添加配置:<task:annotation-driven />
 
配置自动扫描:
<context:component-scan base-package="com.practice.*" />
 
在要进行定时任务的类前加上 @Component
在定时任务的方法上加上 @Scheduled(corn = "")
corn的内容下面介绍
完成后启动项目,springMVC会自动扫描并完成定时任务。我的例子如下:
 
 package com.practice.prac.service.Impl;

 import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date; import javax.annotation.Resource; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service; import com.practice.prac.dao.CreateTableByDayMapper;
import com.practice.prac.service.CreateTableByDayService; @Service("CreateTableByDayService")
@Component
public class CreateTableByDayImpl implements CreateTableByDayService { @Resource
CreateTableByDayMapper createTableByDayMapper; @Override
@Scheduled(cron = "*/5 * * * * ?")
public void createTable() { DateFormat fmt = new SimpleDateFormat("yyyyMMdd");
String time = fmt.format(new Date());
String sql = "create table if not exists table_name_" + time
+ " (name varchar(50),value varchar(50))";
createTableByDayMapper.createTable(sql);
} }

CreateTableByDyImpl.java

corn的配置情况如下:
CRON表达式  含义 
"0 0 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分每分钟一次触发 
"0 0/5 14 * * ?"  每天从下午2点开始到2:55分结束每5分钟一次触发 
"0 0/5 14,18 * * ?"  每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发 
"0 0-5 14 * * ?"   每天14:00至14:05每分钟一次触发 
"0 10,44 14 ? 3 WED" 三月的每周三的14:10和14:44触发 
"0 15 10 ? * MON-FRI" 每个周一、周二、周三、周四、周五的10:15触发
 
具体参见这边博客:http://biaoming.iteye.com/blog/39532

使用SpringMVC自带的@Scheduled完成定时任务的更多相关文章

  1. spring的Scheduled(定时任务)和多线程

    一.前言 在我们日常的开发中,经常用到数据同步的更新,这时我们采用的是spring的定时任务和java的多线程进行数据的更新,进行时实的服务调用. 二.实现思路            1.创建线程类 ...

  2. spring注解scheduled实现定时任务

    只想说,spring注解scheduled实现定时任务使用真的非常简单. 一.配置spring.xml文件 1.在beans加入xmlns:task="http://www.springfr ...

  3. 定时任务-----Springboot中使用Scheduled做定时任务----http://www.cnblogs.com/lirenqing/p/6596557.html

    Springboot中使用Scheduled做定时任务---http://www.cnblogs.com/lirenqing/p/6596557.html 已经验证的方案: pom文件加入依赖 < ...

  4. SpringBoot中使用@Scheduled创建定时任务

    SpringBoot中使用@Scheduled创建定时任务 定时任务一般会在很多项目中都会用到,我们往往会间隔性的的去完成某些特定任务来减少服务器和数据库的压力.比较常见的就是金融服务系统推送回调,一 ...

  5. SpringBoot使用@Scheduled创建定时任务

    定时任务一般会存在中大型企业级项目中,为了减少服务器.数据库的压力往往会采用时间段性的去完成某些业务逻辑.比较常见的就是金融服务系统推送回调,一般支付系统订单在没有收到成功的回调返回内容时会持续性的回 ...

  6. 使用Spring的@Scheduled实现定时任务

    Spring配置文件xmlns加入xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation ...

  7. Springboot中使用Scheduled做定时任务

    在开发中,定时任务是常见的功能,在spring boot 下开发定时任务其实很简单,具体代码如下: 1.配置依赖包pom.xml 由于默认的maven仓库经常访问不了,这里采用了阿里云的maven仓库 ...

  8. 使用Spring的@Scheduled实现定时任务参数详解

    Spring配置文件xmlns加入 xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocati ...

  9. SpringBoot之使用Scheduled做定时任务

    定时任务有好多开源框架比如Quartz,@Scheduled是Spring的一个定时任务注解,通过注解配置就能够轻量级的定时任务,简单方便. 一.@Scheduled注解介绍 这里先贴上@Schedu ...

随机推荐

  1. Hadoop命令别名

    [hadoop@master ~]$ alias hdfs='hadoop dfs' [hadoop@master ~]$ hdfs -ls / drwxrwxr-x   - hadoop super ...

  2. RMAN备份详解

    1.7.1数据库备份与RMAN备份的概念 1.数据库完全备份:按归档模式分为归档和非归档 归档模式 打开状态,属于非一致性备份 关闭状态,可以分为一致性和非一致性 非归档模式 打开状态,非一致性备份无 ...

  3. postgresql数据库创建、修改、删除

    一.数据库创建 语法: Command:     CREATE DATABASEDescription: create a new databaseSyntax:CREATE DATABASE nam ...

  4. CH1301 邻值查找【set应用】

    1301 邻值查找 0x10「基本数据结构」例题 描述 给定一个长度为 n 的序列 A,A 中的数各不相同.对于 A 中的每一个数 A_i,求:min(1≤j<i) ⁡|A_i-A_j|以及令上 ...

  5. 2014年web页面上的3D新产品介绍

    地图对于数据的可视化展现有独到的显示方式,首先是底图.地图提供了一个定位的蓝图,让用例数据可以有参考的背景,因此底图通常是线画矢量图或者影像图.互联网上提供这种服务的基本以Google风格,也就是Ti ...

  6. Chinese_remainder_theorem

    https://en.wikipedia.org/wiki/Chinese_remainder_theorem 中国剩余定理 https://en.wikipedia.org/wiki/RSA_(cr ...

  7. 去掉chrome、safari input或textarea在得到焦点时出现黄色边框的方法

    1.去掉chrome.safari input或textarea在得到焦点时出现黄色边框的方法 input{ outline:0;} 2.去掉chrome.safari textarea右下角可拖动鼠 ...

  8. JSON数组成员反序列化

    场景: 构想客户端能够传递如下格式JSON字符串到服务端: {"KeyValueSetList":[{"SN":"RQ1001"," ...

  9. 12.GIT多人协作

    当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 查看远程库的信息 $ git remote origin $ ...

  10. python pip源配置

    一.Linux版本: linux的文件存放在:~/.pip/pip.conf 二.windows版本: 在用户文件夹下创建pip目录,并在pip目录下创建pip.ini文件(%HOME%\pip\pi ...