参考博客:

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. OpenDayLight Helium实验三 OpenDaylight二层转发机制实验 2

    鉴于在个人笔记本上虚拟机运行ODL实在太慢,把实验的场景搬到了实验室. 实验上:OpenDayLight Helium实验三 OpenDaylight二层转发机制实验 抓包实验 紧接着,在运行Mini ...

  2. ${user.home} is not working in jenkins windows system

    default setting create m2 in C:\Windows\system32\config\systemprofile change it to <localReposito ...

  3. mysql循环查询树状数据

    完整function )) ) CHARSET utf8 BEGIN ) ; ) ; SET str = ''; SET cid =cast(rootId as CHAR); WHILE cid is ...

  4. python学习笔记(HTMLTestRunner在Py3的兼容)

    博主最近开始重构自动化框架并且向Py3上兼容 第一个问题就是生成测试报告的HTMLTestRunner,由于此模块是基于Py2开发的,这里需要修改源码 # 94行 # import StringIO ...

  5. bzoj2152: 聪聪可可 树分治

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

  6. Presto改造

    最近在打造一款可视化分析产品, 需要用到组合多数据源, 进行查询, 看了挺多开源的插件, 发现目前只有Presto比较符合, 但是由于Presto没有多用户机制和资源管理, 所以需要在这基本上构建多用 ...

  7. 在am中定义消息集束,并在CO中验证之后抛出异常。

    需求:在页面上点某个按钮的时候,需要收集所有异常并抛出. -------------------------------------------方式1:参考 EBS OAF开发中的错误/异常处理(Er ...

  8. 自定义jQuery的animate动画

    //擦除效果 jQuery.extend(jQuery.easing, { easeOutBack : function(x, t, b, c, d, s) { s = s || 1.3; retur ...

  9. 物理内存不够用,临时增大Linux交换分区的方法

    当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用.那些被释放的空间可能来自一些很长时间没有什么 操作的程序,这些被释放的空间被临时保存到Swap空间中,等到 ...

  10. SGU 139. Help Needed! 逆序数,奇偶性,分析 难度:0

    139. Help Needed! time limit per test: 0.25 sec. memory limit per test: 4096 KB Little Johnny likes ...