spring整合quartz实现简单的任务调度
2016-08-25 16:13
483 查看
<web.xml> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
<applicationContext.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.xsd"> <!--需要被调度的类--> <bean id="quartzJob" class="com.jetair.quartz.QuartzJob"/> <!--定义要被调用的类和方法--> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!--被调用类--> <property name="targetObject"> <ref bean="quartzJob"/> </property> <!--被调用方法--> <property name="targetMethod"> <value>work</value> </property> </bean> <!--定义触发时间--> <bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <!--被触发类--> <property name="jobDetail"> <ref bean="jobDetail"/> </property> <property name="cronExpression"> <value>5,10,15,20,25,30,35,40,45,50,55 * * * * ?</value> </property> </bean> <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="doTime"/> </list> </property> </bean> </beans>
<QuartzJob.class> package com.jetair.quartz; /** * Created by 22431 on 2016/8/25. */ public class QuartzJob { public void work(){ System.out.println("实现任务调度,实现任务调度,实现任务调度"); } }
<QuertzTest.class> import com.sun.org.apache.xpath.internal.SourceTree; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Created by 22431 on 2016/8/25. */ public class QuartzTest { public static void main(String[] args) { System.out.println("测试开始!"); ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); applicationContext.getBean("startQuertz"); } }
相关文章推荐
- Spring与Quartz的整合实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring整合Quartz实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring整合Quartz实现任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring3.0与Quartz的整合实现定时任务调度
- Spring整合quartz框架实现任务定时调度
- Spring3.0与Quartz的整合实现定时任务调度
- Spring与Quartz的整合实现定时任务调度
- spring整合quartz实现定时任务调度
- Spring整合的quartz任务调度的实现方式
- Spring整合的quartz任务调度的实现方式
- spring 整合quartz实现任务调度
- Spring与Quartz的整合实现定时任务调度
- Spring整合Quartz实现定时任务调度