参考博客:

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. Owin对Asp.net Web的扩展

    类库Microsoft.Owin.Host.SystemWeb 扩展HttpContext以及HttpRequest ,新增了方法GetOwinContext // // Summary: // Pr ...

  2. Ubuntu 安装 Telnet

    参考:在 ubuntu 上安裝 telnet service 1.安装: sudo apt-get install xinetd telnetd 2.修改inetd.conf: vim /etc/in ...

  3. Flask 6 模板2

    NOTE Jinja2提供了多种控制程序,可以用来改变模板的渲染流程. 1.在模板中使用条件控制语句: templates/condition.html: {% if user %} Hello, { ...

  4. springboot logback + log4j2日志管理

    springboot的web项目中自带了日志组件: 我们看一下,springboot中找到日志组件. <dependency> <groupId>org.springframe ...

  5. Qt5_vs2013_error_C2001: 常量中有换行符__资料

    ZC: Win7x64 + Qt551(x86) + vs2013(x86) ZC: 问题:UTF-8 在源码文件中有中文时,有时会报编译错误:C2001 & C2143 分析: --> ...

  6. Cloud Native 环境

    当今软件行业正发生着巨变.自上世纪50年代计算机诞生以来,软件从最初的手工作坊式的交付方式,逐渐演变成为了职业化开发.团队化开发,进而定制了软件件行业的相关规范,形成了软件产业. 今天,无论是大型企业 ...

  7. java中interrupt、join、sleep、notify、notifyAll、wait详解

    首先介绍一下中断概念:举个例子容易理解一点 例子:假如你正在给朋友写信,电话铃响了.这时,你放下手中的笔,去接电话.通话完毕,再继续写信.这个例子就表现了中断及其处理过程:电话铃声使你暂时中止当前的工 ...

  8. 如何修改SQL Server 2008数据库服务器名称

    在做数据库发布订阅的时候我们经常要碰到要使用服务器名称来进行. 那么我们经常会碰到的问题是,现在开始大量的使用云服,我们只需要一台服务器搭建好环境,做一个备份镜像,还原到其他的服务器上就可以了,但是问 ...

  9. 缓存cache(5.2新:redis): gem faker (6600✨) 命令行工具curl(系统内置,可在git上看到文档)

    ⚠️本章节记录缓存的一些方法的用法案例,配合这篇博客一起阅读:https://i.cnblogs.com/EditPosts.aspx?postid=8776632  前置种子 https://git ...

  10. AndroidStudio怎样导入library项目开源库

    AndroidStudio是一款非常强大的android程序开发软件,在里面集成了几乎所有android开发中需要使用的工具,编译.运行.打包.开发.调试等功能一应俱全,可以使用起来非常方便. 今天要 ...