博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring2.5.6下配置定时器
阅读量:4069 次
发布时间:2019-05-25

本文共 2272 字,大约阅读时间需要 7 分钟。

applicationContext.xml 代码如下:

<?xml version="1.0"encoding="UTF-8"?> 

<beansxmlns="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:tx="http://www.springframework.org/schema/tx" 

  xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd 

       http://www.springframework.org/schema/tx  

      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 

      http://www.springframework.org/schema/aop  

      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 

       http://www.springframework.org/schema/context  

      http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 

    <!-- 支持元注释 --> 

   <context:annotation-config /> 

     <!-- 扫描包目录 --> 

   <context:component-scanbase-package="com"></context:component-scan>      

  <importresource="scheduler.xml"/>       

</beans> 

scheduler.xml:代码如下:

<?xml version="1.0" encoding="GBK"?> 

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN""http://www.springframework.org/dtd/spring-beans-2.0.dtd"> 

<beans> 

    <!-- 定时扫描周期,如果已到期,则结束周期 --> 

    <!-- 定时服务定义 -->    

   <beanclass="org.springframework.scheduling.quartz.SchedulerFactoryBean">    

        <!-- 自动启动 -->    

       <propertyname="autoStartup">    

         <value>true</value>    

        </property>    

       <propertyname="triggers">    

           <list>  

               <reflocal="testTrigger"/>   

           </list>    

        </property>    

    </bean>  

   <beanid="testTrigger"class="org.springframework.scheduling.quartz.CronTriggerBean"> 

       <propertyname="jobDetail">    

          <refbean="testJobDetail"/>    

      </property>    

     <propertyname="cronExpression">    

           <!-- 过一秒开始,每间隔两秒执行-->    

            <value>1/2 ** * * ?</value>    

        </property>  

    </bean>  

    <beanid="testJobDetail"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 

        <propertyname="targetObject"> 

            <refbean="testJob"/> 

        </property>    

        <propertyname="targetMethod"> 

           <value>test</value> 

        </property>    

        <propertyname="concurrent" value="false"/>   

    </bean> 

    <beanid="testJob"class="com.jungle.TestJob"></bean> 

</beans> 

 

TestJob类:代码如下:

package com.jungle;   

public class TestJob { 

    public void test() { 

      System.out.println("test!!!");//运行效果是每间隔两秒打印这句话一次。 

   } 

 

 <dependency>

    <groupId>quartz-all</groupId>
    <artifactId>quartz-all</artifactId>
    <version>1.6.1</version>
 </dependency>

jar包下载:

转载地址:http://xshji.baihongyu.com/

你可能感兴趣的文章
【数据结构周周练】002顺序表与链表
查看>>
C++报错:C4700:使用了非初始化的局部变量
查看>>
【数据结构周周练】003顺序栈与链栈
查看>>
C++类、结构体、函数、变量等命名规则详解
查看>>
C++ goto语句详解
查看>>
【数据结构周周练】008 二叉树的链式创建及测试
查看>>
《软件体系结构》 第九章 软件体系结构评估
查看>>
《软件体系结构》 第十章 软件产品线体系结构
查看>>
《软件过程管理》 第六章 软件过程的项目管理
查看>>
《软件过程管理》 第九章 软件过程的评估和改进
查看>>
《软件过程管理》 第八章 软件过程集成管理
查看>>
分治法 动态规划法 贪心法 回溯法 小结
查看>>
《软件体系结构》 练习题
查看>>
《数据库系统概论》 第一章 绪论
查看>>
《数据库系统概论》 第二章 关系数据库
查看>>
《数据库系统概论》 第三章 关系数据库标准语言SQL
查看>>
SQL语句(二)查询语句
查看>>
SQL语句(六) 自主存取控制
查看>>
《计算机网络》第五章 运输层 ——TCP和UDP 可靠传输原理 TCP流量控制 拥塞控制 连接管理
查看>>
堆排序完整版,含注释
查看>>