码迷,mamicode.com
首页 > 编程语言 > 详细

zbb20170227_spring_quartz

时间:2017-02-27 23:02:25      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:html   tac   ping   java   oar   schedule   value   black   add   

一、Spring3+Quartz2整合

1.quartz2所需jar包
  http://download.csdn.net/detail/bobchao0730/9479097
技术分享
技术分享
2.spring-task.xml
[html] view plain copy
 
 技术分享技术分享
  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"   
  4.     xmlns:p="http://www.springframework.org/schema/p"  
  5.     xmlns:tx="http://www.springframework.org/schema/tx"    
  6.     xmlns:aop="http://www.springframework.org/schema/aop"    
  7.     xmlns:context="http://www.springframework.org/schema/context"   
  8.     xmlns:mvc="http://www.springframework.org/schema/mvc"     
  9.     xsi:schemaLocation="  
  10.         http://www.springframework.org/schema/beans   
  11.         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  12.         http://www.springframework.org/schema/aop   
  13.         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
  14.         http://www.springframework.org/schema/context   
  15.         http://www.springframework.org/schema/context/spring-context-3.0.xsd   
  16.         http://www.springframework.org/schema/tx   
  17.         http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   
  18.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd        
  19.         ">  
  20.         <!-- 使用MethodInvokingJobDetailFactoryBean,任务类可以不实现Job接口,通过targetMethod指定调用方法 -->  
  21.         <bean id="taskJob" class="com.ky.task.MyTask"></bean>  
  22.         <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
  23.             <property name="group" value="job_work"/>  
  24.             <property name="name" value="job_work_name"/>  
  25.             <!-- false表示等上一个任务执行完成后再开启新的任务 -->  
  26.             <property name="concurrent" value="false"/>  
  27.             <property name="targetObject">  
  28.                 <ref bean="taskJob"/>  
  29.             </property>  
  30.             <property name="targetMethod">  
  31.                 <value>run</value>  
  32.             </property>  
  33.         </bean>  
  34.           
  35.         <!-- 调度触发器 -->  
  36.         <bean id="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">  
  37.             <property name="group" value="work_default"/>  
  38.             <property name="name" value="work_default_name"/>  
  39.             <property name="jobDetail">  
  40.                 <ref bean="jobDetail"/>  
  41.             </property>  
  42.             <!-- 每天0点执行 -->  
  43.             <property name="cronExpression">  
  44.                 <value>0/5 * * * * ?</value>  
  45.             </property>  
  46.         </bean>  
  47.         <!-- 调度工厂 -->  
  48.         <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
  49.             <property name="triggers">  
  50.                 <list>  
  51.                     <ref bean="myTrigger"/>  
  52.                 </list>  
  53.             </property>  
  54.         </bean>  
  55. </beans>  
3.web.xml
[html] view plain copy
 
 技术分享技术分享
  1. <!-- 配置spring mvc -->
    <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:com/zbb/config/spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>

     
4.MyTask .java
[java] view plain copy
 
 技术分享技术分享
  1. package com.ky.task;  
  2. public class MyTask {  
  3. public void run() {  
  4.         System.out.println("每天0点执行!");  
  5.     }  
}

 

zbb20170227_spring_quartz

标签:html   tac   ping   java   oar   schedule   value   black   add   

原文地址:http://www.cnblogs.com/super-admin/p/6476759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!