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设置定时器配置的更多相关文章

  1. SSH框架中 Spring设置定时器 Quartz

    一,首先下载quartz-1.6.0.jar架包,到lib目录下 二,写你自己定时器业务方法 package com.lbnet.lzx.timing; import org.quartz.JobEx ...

  2. spring task定时器的配置使用

    spring task的配置方式有两种:配置文件配置和注解配置. 1.配置文件配置 在applicationContext.xml中增加spring task的命名空间: xmlns:task=&qu ...

  3. 自定义的Spring Boot starter如何设置自动配置注解

    本文首发于个人网站: 在Spring Boot实战之定制自己的starter一文最后提到,触发Spring Boot的配置过程有两种方法: spring.factories:由Spring Boot触 ...

  4. 基于注解的Spring多数据源配置和使用

    前一段时间研究了一下spring多数据源的配置和使用,为了后期从多个数据源拉取数据定时进行数据分析和报表统计做准备.由于之前做过的项目都是单数据源的,没有遇到这种场景,所以也一直没有去了解过如何配置多 ...

  5. SPRING SECURITY JAVA配置:Web Security

    在前一篇,我已经介绍了Spring Security Java配置,也概括的介绍了一下这个项目方方面面.在这篇文章中,我们来看一看一个简单的基于web security配置的例子.之后我们再来作更多的 ...

  6. 从零开始学 Java - Spring 集成 ActiveMQ 配置(二)

    从上一篇开始说起 上一篇从零开始学 Java - Spring 集成 ActiveMQ 配置(一)文章中讲了我关于消息队列的思考过程,现在这一篇会讲到 ActivMQ 与 Spring 框架的整合配置 ...

  7. 基于xml的Spring多数据源配置和使用

    上一篇讲了<基于注解的Spring多数据源配置和使用>,通过在类或者方法上添加@DataSource注解就可以指定某个数据源.这种方式的优点是控制粒度细,也更灵活. 但是当有些时候项目分模 ...

  8. spring设置全局异常处理器

    1.spring设置全局异常,它的原理是向上捕获 spring.xml配置 <!--自定义全局异常处理器--> <bean id="globalExceptionResol ...

  9. spring的定时任务配置

    本文来源于:http://myspace1916.iteye.com/blog/1570707 也可参考:http://www.oschina.net/question/8676_9032 (个人只是 ...

随机推荐

  1. MYSQL中写SQL语句,取到表中按ID降序排列(最新纪录排在第一行)

    'select * from bugdata where id>0 order by id desc'

  2. bzoj 5020(洛谷4546) [THUWC 2017]在美妙的数学王国中畅游——LCT+泰勒展开

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5020 https://www.luogu.org/problemnew/show/P4546 ...

  3. wheezy下安装emacs24

    wget -q -O - http://emacs.naquadah.org/key.gpg | sudo apt-key add - vim /etc/apt/sources.list 添加 deb ...

  4. Linux新手入门:Unable to locate package错误解决办法

    最近刚开始接触Linux,在虚拟机中装了个Ubuntu,当前的版本是Ubuntu 11.10,装好后自然少不了安装一些软件,在设置了软件的源后,就开始了 sudo apt-get install,结果 ...

  5. codeforce1029B B. Creating the Contest(简单dp,简单版单调栈)

    B. Creating the Contest time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. Bootstrap-CL:导航栏

    ylbtech-Bootstrap-CL:导航栏 1.返回顶部 1. Bootstrap 导航栏 导航栏是一个很好的功能,是 Bootstrap 网站的一个突出特点.导航栏在您的应用或网站中作为导航页 ...

  7. 1.2 auth2.0

    多个应用 入sina  qq  msn  豆瓣 等 在手机登录时或终端登录时如果统一可以根据硬件做 gettid()-为了保证唯一性:方案一:      事先生成唯一验证码:使用一个isue 设置为1 ...

  8. JDK8时间格式转换

    来源:https://blog.csdn.net/zhangzijiejiayou/article/details/76597329 LocalDateTime 本地日期时间 LocalDateTim ...

  9. jsp 学习 第2步 - tag 使用

    tag  类似 asp.net 用户控件,用于动态显示HTML 我首先在项目 /WebContent/WEB-INF/  建立 tags目录 用于存放 tag文件 新建一个message.tag 文件 ...

  10. 可视化库-Matplotlib-散点图(第四天)

    1. 画基本的散点图 plt.scatterdata[:, 0], data[:, 1], marker='o', color='r', label='class1', alpha=0.4) np.r ...