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 (个人只是 ...
随机推荐
- UOJ 347(洛谷4220) 【WC2018】通道——随机化
题目:http://uoj.ac/problem/347 https://www.luogu.org/problemnew/show/P4220 先写了暴力分的44分.那个两棵树.其中一棵是编号连续的 ...
- 跟着TensorFlow的进阶级教程实现MNIST库的训练
转载出处:http://blog.csdn.net/feifei884431/article/details/51429829 背景介绍 代码实现及结果 小问题 ResourceExhaustedE ...
- WebService返回json格式数据供苹果或者安卓程序调用
1.新建一个WebService. 2. /// <summary> /// DemoToJson 的摘要说明 /// </summary> [WebService(Names ...
- xlrd库的使用
- ESN
1.对于一般的硬件设备,ESN是设备序列号,主要用来识别设备,包括未来服务鉴权的需要 2.对于需要license的设备,ESN也是设备序列号的意思,只不过这个序列号可能是根据设备硬件信息算出来的一串字 ...
- php 数字格式化
php 数字格式化 1.位数不足前面补0 <?php for($i=1; $i<=17 ;$i++){ $var = sprintf("0%3d",$i); echo ...
- modelsim 仿真xilinx fir ip
到现在不管fir ip 用的对不对,但是在使用modelsim是可以仿真fir ip的. 具体步骤: 1.仿真库,添加到modelsim目录配置文件: 2.将这个文件中的: :List of dyna ...
- 并发包学习(一)-Atomic包小记
此篇是J.U.C学习的第一篇Atomic包相关的内容,希望此篇总结能对自己的基础有所提升.本文总结来源自<Java并发编程的艺术>第七章并配以自己的实践理解.如有错误还请指正. 一.案例分 ...
- GridEh排序
添加pas文件 EhLibADO.pas EhLibCDS.pas EhLibFireDAC.pas 支持FireDAC 设置GridEh的属性 DBGridEh1->SortLocal = t ...
- Redhat 7.2 编译安装PostgreSQL 10
1.环境说明 CentOS7.2 postgresql10.4 2.下载 postgresql的官方地址 https://www.postgresql.org/ftp/source/ 在下载列表中根据 ...