Spring设置定时器配置
corn表达式生成:http://www.pppet.net/
1.注解方式
添加命名空间
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd
task任务扫描注解
<task:annotation-driven/>
spring扫描位置
<context:annotation-config/>
<context:component-scan base-package="com.test"/>
定时任务
@Scheduled(cron="0/5 * * * * ? ") //每5秒执行一次
public void myTest(){
System.out.println("进入测试");
}
注意:定时器的任务方法不能有返回值(如果有返回值,spring初始化的时候会告诉你有个错误、需要设定一个proxytargetclass的某个值为true)
2.xml方式
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <!-- 定时任务 -->
<bean id="venueLockerRecordJob" class="com.rdkl.qmjs.job.VenueLockerRecordJob"/>
<bean id="venueLockerRecordJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="venueLockerRecordJob" />
<property name="targetMethod" value="updateStatus" />
<!-- false:不允许并发执行 -->
<property name="concurrent" value="false" />
</bean>
<bean id="venueSettlementJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="description" value="更新储物柜租用状态" />
<property name="jobDetail" ref="venueLockerRecordJobDetail" />
<!-- 凌晨2点执行 0 0 2 * * ? -->
<property name="cronExpression" value="0 0 12 * * ?" />
</bean>
<!-- 定时任务配置 结束 --> <!-- schedulerFactory -->
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="venueSettlementJobTrigger" />
</list>
</property>
</bean>
</beans>
Spring设置定时器配置的更多相关文章
- SSH框架中 Spring设置定时器 Quartz
		
一,首先下载quartz-1.6.0.jar架包,到lib目录下 二,写你自己定时器业务方法 package com.lbnet.lzx.timing; import org.quartz.JobEx ...
 - spring task定时器的配置使用
		
spring task的配置方式有两种:配置文件配置和注解配置. 1.配置文件配置 在applicationContext.xml中增加spring task的命名空间: xmlns:task=&qu ...
 - 自定义的Spring Boot starter如何设置自动配置注解
		
本文首发于个人网站: 在Spring Boot实战之定制自己的starter一文最后提到,触发Spring Boot的配置过程有两种方法: spring.factories:由Spring Boot触 ...
 - 基于注解的Spring多数据源配置和使用
		
前一段时间研究了一下spring多数据源的配置和使用,为了后期从多个数据源拉取数据定时进行数据分析和报表统计做准备.由于之前做过的项目都是单数据源的,没有遇到这种场景,所以也一直没有去了解过如何配置多 ...
 - SPRING SECURITY JAVA配置:Web Security
		
在前一篇,我已经介绍了Spring Security Java配置,也概括的介绍了一下这个项目方方面面.在这篇文章中,我们来看一看一个简单的基于web security配置的例子.之后我们再来作更多的 ...
 - 从零开始学 Java - Spring 集成 ActiveMQ 配置(二)
		
从上一篇开始说起 上一篇从零开始学 Java - Spring 集成 ActiveMQ 配置(一)文章中讲了我关于消息队列的思考过程,现在这一篇会讲到 ActivMQ 与 Spring 框架的整合配置 ...
 - 基于xml的Spring多数据源配置和使用
		
上一篇讲了<基于注解的Spring多数据源配置和使用>,通过在类或者方法上添加@DataSource注解就可以指定某个数据源.这种方式的优点是控制粒度细,也更灵活. 但是当有些时候项目分模 ...
 - spring设置全局异常处理器
		
1.spring设置全局异常,它的原理是向上捕获 spring.xml配置 <!--自定义全局异常处理器--> <bean id="globalExceptionResol ...
 - spring的定时任务配置
		
本文来源于:http://myspace1916.iteye.com/blog/1570707 也可参考:http://www.oschina.net/question/8676_9032 (个人只是 ...
 
随机推荐
- centos下memcached安装
			
memcached是一款高速.分布式的内存缓存系统.其官方主页在http://www.danga.com/memcached/ 1.安装前的准备 要安装memcached,需要有libevent的支持 ...
 - 【linux】ls常用参数
			
1. 命令格式: ls [选项] [目录名] 2. 命令功能: 列出目标目录中所有的子目录和文件. 3. 常用参数: -a, –-all 列出目录下的所有文件,包括以 . 开头的隐含文件 -d, –- ...
 - Oracle SYS_CONTEXT用法
			
1. USERENV(OPTION) 返回当前的会话信息. OPTION='ISDBA'若当前是DBA角色,则为TRUE,否则FALSE. OPTION='LANGUAGE'返回数据库的字符集. OP ...
 - mysql中去重 distinct 用法
			
在使用MySQL时,有时需要查询出某个字段不重复的记录,这时可以使用mysql提供的distinct这个关键字来过滤重复的记录,但是实际中我们往往用distinct来返回不重复字段的条数(count( ...
 - TS流解析 一
			
一 从TS流开始 数字电视机顶盒接收到的是一段段的码流,我们称之为TS(Transport Stream,传输流),每个TS流都携带一些信息,如Video.Audio以及我们需要学习的PAT.PMT等 ...
 - 黄聪:C#使用能够foreach对hashtable、List遍历时“集合已修改;可能无法执行枚举操作。”错误
			
解决办法:使用for循环,而不是foreach循环 例如: ArrayList akeys=new ArrayList(_transmit_tb.Keys); ;p> -;p--) { _tra ...
 - mysql5.7.12/13在安装新实例时报错:InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero
			
.bin/mysqld --initialize-insecure --basedir=xxx --datadir=xxx 然后 .bin/mysqld_safe --defaults-file=xx ...
 - [置顶]
        Ubuntu16.04+opencv3.3.0的安装配置说明
			
系统环境: Linux Ubuntu 16.04 [GCC 5.4.0 20160609] on linux2 之前的教程中我们已经安装了做机器学习需要使用的框架TensorFlow,笔者本科阶段 ...
 - WCF传输大数据 --断点续传(upload、download)
			
using System; using System.IO; using System.Runtime.Serialization; using System.ServiceModel; namesp ...
 - 软件测试——等价类划分(EditText * 3)
			
一.程序要求 EditBox 同时允许输入三个1到6个英文字符或数字,点击确定结束. 二.测试分析 编号 第一个输入框 第二个输入框 第三个输入框 输出 1 null null null 三个输入框均 ...