参考博客:

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. bzoj2152: 聪聪可可 树分治

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

  2. 【转】ubuntu下修改文件夹权限

    常用方法如下: sudo chmod 600 ××× (只有所有者有读和写的权限)sudo chmod 644 ××× (所有者有读和写的权限,组用户只有读的权限)sudo chmod 700 ××× ...

  3. 在请求的参数中设置可选值列表为当前职责可访问的所有OU

    方法一: 实现此需求的前提之一是为该请求开启多业务实体访问,开启方法 系统管理员->系统管理->并发->程序,进入OAF页面,查询你的并发,然后点更新,选择请求,在业务实体模式下选择 ...

  4. nodejs 前端工具总结

    htmlhint https://github.com/yaniswang/HTMLHint 使用 var HTMLHint = require("htmlhint").HTMLH ...

  5. Hadoop1.2.1完全分布模式安装教程

    假设有三台机器,它们的IP地址和对应的主机名为: 192.168.12.18           localhost.localdomain 192.168.2.215           rhel5 ...

  6. 《BAT前端进阶[师徒班]》学习总结

    这是一个培训课 是的,这是一个面向中级前端的培训班,但明显跟传统的填鸭式培训班不太一样.这边的老师都是大牛这是毫无疑问的,而且都是一线开发人员.而且课程一开始就说明了面向了是有1-3年有工作经验的前端 ...

  7. CF86D

    题解: 莫队分块 分块大小为sqrt(n) 代码: #include<bits/stdc++.h> using namespace std; ; typedef long long ll; ...

  8. phpstudy2017版本的nginx 支持laravel 5.X配置

    之前做开发和学习一直用phpstudy的mysql服务,确实很方便,开箱即用.QQ群交流:697028234 现在分享一下最新版本的phpstudy2017 laravel环境配置. 最新版的phps ...

  9. 基于js-spark-md5前端js类库,快速获取文件Md5值

    js-spark-md5是歪果仁开发的东西,有点多,但是我们只要一个js文件即可,具体类包我存在自己的oschina上,下载地址:https://git.oschina.net/jianqingwan ...

  10. 【python】venv使用

    virtualenvwrapper 比 virualenv 好用一些. 准备 export WORKON_HOME=~/venv source /usr/bin/virtualenvwrapper.s ...