参考博客:

http://www.jb51.net/article/110541.htm

http://blog.csdn.net/wxwzy738/article/details/25158787

我这边项目的需求是:每天晚上1点删除数据库表t_tempclob中的所有记录;

代码:

Controller:

@Controller
public class AjaxFileDownload { private static Logger logger = Logger.getLogger(AjaxFileDownload.class); @Autowired
private ProductService productService; @Autowired
private TempClobService tcService; /**
* 定时任务,每天晚上1点删除数据表t_tempClob中的所有记录
*/
@Scheduled(cron= "0 0 1 * * ?")
public void deleteAllTempClob(){
int count = tcService.deleteAllTempClob();
System.err.println("---->>deleteAllTempClob删除数据库记录数:" + count);
}
}

Service:

/**
* 删除所有大文本
*/
public int deleteAllTempClob(){
int count = 0;
try {
count = tcMapper.deleteAllTempClob();
} catch (Exception e) {
e.printStackTrace();
} return count;
}

Mapper接口:

public interface TempClobMapper {

    /**
* 删除所有的大文本
*/
public int deleteAllTempClob() throws Exception;
}

Mapper.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cy.dao.TempClobMapper" > <!-- 删除所有的大文本 -->
<delete id="deleteAllTempClob">
delete from t_tempclob
</delete> </mapper>

spring-mvc.xml中关于task的配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd"> <!-- 使用注解的包,包括子集 -->
<context:component-scan base-package="com.cy.controller" /> <!-- 定时器开关-->
<task:annotation-driven /> </beans>

cron表达式详解、举例子:

https://www.cnblogs.com/javahr/p/8318728.html

cron表达式说明:

参考博客:http://www.jb51.net/article/110541.htm

spring的定时任务配置(注解)的更多相关文章

  1. spring的定时任务配置

    本文来源于:http://myspace1916.iteye.com/blog/1570707 也可参考:http://www.oschina.net/question/8676_9032 (个人只是 ...

  2. Spring的定时任务配置2(转)

    spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 1.定义任务 <!--要定时执行的方法--> <bean id="testTas ...

  3. Spring的定时任务配置(转)

    spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 1.定义任务 <!--要定时执行的方法--> <bean id="testTas ...

  4. spring自定义自动配置注解

    我们知道springboot自动配置@EnableAutoConfiguration是通过@Import(AutoConfigurationImportSelector.class)来把自动配置组件加 ...

  5. Spring.xml中配置注解context:annotation-config和context:component-scan简述

    XML中context:annotation-config和context:component-scan简述 <context:annotation-config/> 中文意思:<上 ...

  6. Spring 自动定时任务配置

    Spring中可以通过配置方便的实现周期性定时任务管理,这需要用到以下几个类: org.springframework.scheduling.quartz.MethodInvokingJobDetai ...

  7. Spring Boot定时任务配置

    import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.a ...

  8. spring + Quartz定时任务配置

    <bean id="exportBatchFileTask" class="com.ydcn.pts.task.ExportBatchFileTask"& ...

  9. spring quartz定时任务 配置

    cronExpression表达式: 字段 允许值 允许的特殊字符秒 0-59 , - * /分 0-59 , - * /小时 0-23 , - * /日期 1-31 , - * ? / L W C月 ...

随机推荐

  1. 基于Oracle Sequence的流水号生成规则

    流水号在各种系统中随处可见,一般都是使用自增.年月日时分秒+自增.UUID等,要么纯数字,要么纯字母,这种流水号缺乏一定的辨识度. 下面为大家介绍一种具有辨识度的流水号的生成方式:领域或者应用的标识 ...

  2. js的重载

    1.重载 //重载(个数不同,类型不同)function prop(){var firstP = document.getElementById("p");if(arguments ...

  3. [fastjson] - fastjson中 JSONObject 和 JSONArray

    /** * 对jsonObject对象进行key的获取 * @param jsonObject */ public ArrayList<String> jsonKeyRecursion(J ...

  4. Gym - 100283F Bakkar In The Army(二分)

    https://vjudge.net/problem/Gym-100283F 题意: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 .... 给出这样的序列,然后给出一个n,计算从1 ...

  5. Eclipse.修改项目的JDK版本

    1.我实际使用过程中,只是修改了 项目右键-->Properties-->左侧选择"Java Compiler" -->右侧的"JDK Complian ...

  6. Java IO流-合并流

    2017-11-05 20:15:28 SequenceinputStream SequenceinputStream:SequenceInputStream 表示其他输入流的逻辑串联.它从输入流的有 ...

  7. JavaScript--变量和运算符

    JavaScript--变量和运算符 一.心得 JavaScript语法:变量声明 var弱类型 var中可以是任何类型在JavaScript里面,单&单|是位运算符.变量没有值使用的话就是u ...

  8. bzoj2152: 聪聪可可 树分治

    sb树分治 /************************************************************** Problem: 2152 User: walfy Lang ...

  9. SpringMvc测试框架详解----服务端测试

    随着RESTful Web Service的流行,测试对外的Service是否满足期望也变的必要的.从Spring 3.2开始Spring了Spring Web测试框架,如果版本低于3.2,请使用sp ...

  10. bzoj4811

    题解: 对于每一个节点,我们建立v0,v1 v0表示0进过会怎么样 v1表示1进过会怎么样 然后线段树合并 代码: #include <cstdio> #include <cstri ...