spring的定时任务配置(注解)
参考博客:
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的定时任务配置(注解)的更多相关文章
- spring的定时任务配置
本文来源于:http://myspace1916.iteye.com/blog/1570707 也可参考:http://www.oschina.net/question/8676_9032 (个人只是 ...
- Spring的定时任务配置2(转)
spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 1.定义任务 <!--要定时执行的方法--> <bean id="testTas ...
- Spring的定时任务配置(转)
spring的定时任务配置分为三个步骤: 1.定义任务 2.任务执行策略配置 3.启动任务 1.定义任务 <!--要定时执行的方法--> <bean id="testTas ...
- spring自定义自动配置注解
我们知道springboot自动配置@EnableAutoConfiguration是通过@Import(AutoConfigurationImportSelector.class)来把自动配置组件加 ...
- Spring.xml中配置注解context:annotation-config和context:component-scan简述
XML中context:annotation-config和context:component-scan简述 <context:annotation-config/> 中文意思:<上 ...
- Spring 自动定时任务配置
Spring中可以通过配置方便的实现周期性定时任务管理,这需要用到以下几个类: org.springframework.scheduling.quartz.MethodInvokingJobDetai ...
- Spring Boot定时任务配置
import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.a ...
- spring + Quartz定时任务配置
<bean id="exportBatchFileTask" class="com.ydcn.pts.task.ExportBatchFileTask"& ...
- spring quartz定时任务 配置
cronExpression表达式: 字段 允许值 允许的特殊字符秒 0-59 , - * /分 0-59 , - * /小时 0-23 , - * /日期 1-31 , - * ? / L W C月 ...
随机推荐
- 防止putty的鼠标右键错误粘贴
一.环境 发行版:Ubuntu 18.04.1 LTS 代号:bionic 内核版本:4.15.0-30-generic 二.背景 每次从putty复制时,会单击鼠标右击,以便复制出终端的内容,但是一 ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- [Pytorch]Pytorch 细节记录(转)
文章来源 https://www.cnblogs.com/king-lps/p/8570021.html 1. PyTorch进行训练和测试时指定实例化的model模式为:train/eval eg: ...
- codeforces 98 div2 C.History 水题
C. History time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- package 'yaml-cpp' not found
-- Using these message generators: gencpp;genlisp;genpy -- checking for module 'yaml-cpp' -- package ...
- sapply
列表并非总是存储结果的最佳容器.有时,我们希望将结果放在一个向量或者矩阵中.sapply( )函数可以根据结果的结构将其合理简化.假设,我们将平方运算应用到 1:10 的每个元素上.如果使用 lapp ...
- 【整理】STL中的bitset(二进制华丽解决假五维偏序题)
------------更多Bitset的运用,请看这里http://www.cnblogs.com/hua-dong/p/8519739.html. 由于在学cdq分治,看到了这道题.先来看一道题目 ...
- 用Python操作Named pipe命名管道,实用做法——os.read 或 os.write
https://blog.csdn.net/mayao11/article/details/50618598
- iOS导航栏的正确隐藏方式
在项目中经常碰到首页顶部是无限轮播,需要靠最上面显示.有的设置导航栏为透明等一系列的方法,这个可以借助第三方.或者干脆简单粗暴的直接隐藏掉导航栏.可是push到下一个页面的时候是需要导航栏的,如何做了 ...
- php http build query
http_build_query (PHP 5, PHP 7) http_build_query — 生成 URL-encode 之后的请求字符串 说明¶ string http_build_quer ...