要使用定时任务,需要将quartz-1.5.2.jar加入lib,没有的话可以从下面地址下载:

quartz-1.5.2.jar

有了这个再做个配置文件appctx-quartz.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    <bean id="schedulerFactory"    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref local="cronTriggerTest" />
            </list>
        </property>
    </bean> 

    <bean id="cronTriggerTest" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobTest" />
        <property name="cronExpression">
                <value>0 17 21 ? * SAT</value> <!-- FORMAT:second minute hour ? * Weekday -->
        </property>
    </bean>    

    <bean id="jobTest"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="claimScheduler" />
        <property name="targetMethod" value="print" />
    </bean>

    <bean id="claimScheduler" class="com.ufo.unknown.quartz.Test">
    </bean>
</beans>

被调用的类如下:

package com.ufo.unknown.quartz;

public class Test{
    public void print(){
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    }
}

然后在周六的21点17分0秒,Test类的print函数就被调用了,控制台输出如下:

DEBUG (JobRunShell.java:202) - Calling execute on job DEFAULT.jobTest
DEBUG (CachedIntrospectionResults.java:222) - Getting BeanInfo for class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob]
DEBUG (CachedIntrospectionResults.java:238) - Caching PropertyDescriptors for class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob]
DEBUG (CachedIntrospectionResults.java:250) - Found bean property 'class' of type [java.lang.Class]
DEBUG (CachedIntrospectionResults.java:250) - Found bean property 'methodInvoker' of type [org.springframework.util.MethodInvoker]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Spring3的quartz定时任务的更多相关文章

  1. Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  2. quartz定时任务框架的使用

    quartz定时任务时间设置 这些星号由左到右按顺序代表 :     *    *     *     *    *     *   *                                 ...

  3. Quartz定时任务学习(二)web应用

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  4. Quartz定时任务使用小记(11月22日)

    骤然接触quartz,先从小处着手,why,what,how quartz定时任务: 为什么使用quartz定时任务,以及定时任务在实际应用场景下的特定需求. 1.用户方面的需要,为了提供更好的使用体 ...

  5. quartz定时任务时间配置

    quartz定时任务时间设置描述(2011-03-03 16:23:50)转载▼标签: quartz时间it 分类: 凌乱小记  这些星号由左到右按顺序代表 :     *    *     *    ...

  6. 对quartz定时任务的初步认识

    已经好久没有写技术博文了,今天就谈一谈我前两天自学的quartz定时任务吧,我对quartz定时任务的理解,就是可以设定一个时间,然后呢,在这个时间到的时候,去执行业务逻辑,这是我的简单理解,接下来看 ...

  7. Spring整合Quartz定时任务执行2次,Spring定时任务执行2次

    Spring整合Quartz定时任务执行2次,Spring定时任务执行2次 >>>>>>>>>>>>>>>&g ...

  8. Quartz 定时任务时间设置

    转自https://blog.csdn.net/zdx1515888659/article/details/79158169 quartz定时任务时间设置: 这些星号由左到右按顺序代表 : * * * ...

  9. quartz定时任务及时间设置

    quartz 定时任务时间设置1.这些星号由左到右按顺序代表 :     *    *     *     *    *     *   *                               ...

随机推荐

  1. xdebug使用教程

    http://www.cnblogs.com/xujian2016/p/5548921.html 配置信息 zend_extension="D:\phpStudy\php53n\ext\ph ...

  2. Hibernate中映射一对一关联(按主键映射和外键映射)和组件映射

                                                        Hibernate中映射一对一关联(按主键映射和外键映射)和组件映射 Hibernate提供了两 ...

  3. sqlalchemy多表查询

    from datetime import datetime from sqlalchemy import Column,Integer,String,Boolean,DateTime,ForeignK ...

  4. eclipse easy shell plugin

    svn checkout svn://svn.code.sf.net/p/pluginbox/code/trunk pluginbox-code   Eclipse中Easy Shell插件配置Pow ...

  5. 使用 WideCharToMultiByte Unicode 与 UTF-8互转

    1.简述 最近在发送网络请求时遇到了中文字符乱码的问题,在代码中调试字符正常,用抓包工具抓的包中文字符显示正常,就是发送到服务器就显示乱码了,那就要将客户端和服务器设置统一的编码(UTF-8),而我们 ...

  6. 5.DataFrame(基本概念)

  7. python接口自动化10-token登录【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/python%E6%8E%A5%E5%8F%A3%E8%87%AA%E5%8A%A8%E ...

  8. hdu 5109(构造数+对取模的理解程度)

    Alexandra and A*B Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  9. PhpStrom弹窗License activation 报 this license BIG3CLIK6F has been cancelled 错误的解决。

    将“0.0.0.0 account.jetbrains.com”添加到hosts文件中

  10. 网盘+SVN

    1.安装网盘 选择一个国内有名的网盘存储,例如金山网盘.360云盘等,注册账户会默认赠送几G的使用空间,然后下载其对应的网盘客户端管理软件(也可以使用浏览器方式),使用账号登录,就可以上传.管理文件等 ...