zoukankan      html  css  js  c++  java
  • 关于Spring整合quartz的定时任务

     

     

    首先是配置spring监听到web.xml中

    [java] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. <listener>  
    2.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    3.     </listener>   
    4.     <context-param>  
    5.         <param-name>contextConfigLocation</param-name>  
    6.         <param-value>/WEB-INF/conf/applicationContext-bl.xml</param-value>  
    7.     </context-param>  
      然后整合spring和quart
    [java] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. <?xml version="1.0" encoding="UTF-8"?>  
    2. <beans xmlns="http://www.springframework.org/schema/beans"  
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
    4.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
    5.      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  
    6.   
    7.     <!-- 启动触发器的配置开始 -->  
    8.     <bean name="startQuertz" lazy-init="false" autowire="no"  
    9.         class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
    10.         <property name="triggers">  
    11.             <list>  
    12.                 <ref bean="myJobTrigger" /><!--当然一个scheduler可以管理多个trigger,只需在list中配置即可-->  
    13.             </list>  
    14.         </property>  
    15.     </bean>  
    16.     <!-- 启动触发器的配置结束 -->  
    17.   
    18.     <!-- 调度的配置开始 -->  
    19.     <!--  
    20.         quartz-1.8以前的配置   
    21.     <bean id="myJobTrigger"  
    22.         class="org.springframework.scheduling.quartz.CronTriggerBean">  
    23.         <property name="jobDetail">  
    24.             <ref bean="myJobDetail" />  
    25.         </property>  
    26.         <property name="cronExpression">  
    27.             <value>0/1 * * * * ?</value>  
    28.         </property>  
    29.     </bean>  
    30.     -->  
    31.     <!-- quartz-2.x的配置 -->  
    32.     <bean id="myJobTrigger"  
    33.         class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">  
    34.         <property name="jobDetail">  
    35.             <ref bean="myJobDetail" />  
    36.         </property>  
    37.         <property name="cronExpression">  
    38.             <value>60 * * * * ?</value>  
    39.         </property>  
    40.     </bean>  
    41.     <!-- 调度的配置结束 -->  
    42.   
    43.     <!-- job的配置开始 -->  
    44.     <bean id="myJobDetail"  
    45.         class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
    46.         <property name="targetObject">  
    47.             <ref bean="myJob" />  
    48.         </property>  
    49.         <property name="targetMethod">  
    50.             <value>work</value>  
    51.         </property>  
    52.     </bean>  
    53.     <!-- job的配置结束 -->  
    54.   
    55.     <!-- 工作的bean -->  
    56.     <bean id="myJob" class="com.ssh.common.quartz.MyJob" />  
    57.   
    58. </beans>  
  • 相关阅读:
    C# NameValueCollection
    visual studio使用技巧创建自己代码片段
    C#在DataTable中使用LINQ
    [转]C# 中的.pdb/ .vshost.exe/ .vshost.exe.manifest文件讨论
    C#自定义控件在添加引用后不显示在工具箱的解决方法
    Java 工程师
    redis-CRC16
    sql server-当天日期减去一天 应该如何写
    清除访问Windows共享时缓存的凭据
    cmd下查看当前登陆用户
  • 原文地址:https://www.cnblogs.com/originate918/p/6513379.html
Copyright © 2011-2022 走看看