Quartz+spring实例应用
2011-08-15 10:32
330 查看
iLife's 博客http://blog.csdn.net/fei1502816
1. javabean类
在Test.QuartzJob中
2. 设置Spring的xml
我新建了一个applicationContext_quartz.xml,内容如下:
3. 设置web.xml对Spring加载
注意:1.导入quartz-all-1.5.2.jar 下载http://download.csdn.net/source/1026766
2.导入spring.jar(我用的是spring2.0以前的版本) 下载http://download.csdn.net/source/1041819
如果不导入的话
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
org.springframework.scheduling.quartz.CronTriggerBean
org.springframework.scheduling.quartz.SchedulerFactoryBean
spring中的这三个类找不到,spring不能正常加载,由于第一次使用Quartz,我就是当时忽略了这一点,浪费了很多时间来调配置,其实配置一点没有错误。
3. 你会问为什么用spring后就不用
quartz.properties
quartz-jobsxml
这两个文件了么?
我回答:是的,它会自动找到quartz包中默认的这两个文件,如果你有特殊需要,也可以自己定义这两个文件。
附:quartz.properties
系统会根据配置文件找到quartz_jobs.xml
我转载的 有什么不明白得地方敬请访问
iLife's 博客http://blog.csdn.net/fei1502816
1. javabean类
在Test.QuartzJob中
package Test; public class QuartzJob { public void work() { System.out.println("Quartz的任务调度!!!"); } }
2. 设置Spring的xml
我新建了一个applicationContext_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" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"> <!-- 要调用的工作类 --> <bean id="quartzJob" class="Test.QuartzJob"></bean> <!-- 定义调用对象和调用对象的方法 --> <bean id="jobtask" 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.CronTriggerBean"> <property name="jobDetail"> <ref bean="jobtask"/> </property> <!-- cron表达式 --> <property name="cronExpression"> <!-- 每隔10秒执行一次--> <value>0/10 * * * * ?</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>
3. 设置web.xml对Spring加载
<!-- 加载spring --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/classes/applicationContext*.xml </param-value> </context-param> <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet>
注意:1.导入quartz-all-1.5.2.jar 下载http://download.csdn.net/source/1026766
2.导入spring.jar(我用的是spring2.0以前的版本) 下载http://download.csdn.net/source/1041819
如果不导入的话
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
org.springframework.scheduling.quartz.CronTriggerBean
org.springframework.scheduling.quartz.SchedulerFactoryBean
spring中的这三个类找不到,spring不能正常加载,由于第一次使用Quartz,我就是当时忽略了这一点,浪费了很多时间来调配置,其实配置一点没有错误。
3. 你会问为什么用spring后就不用
quartz.properties
quartz-jobsxml
这两个文件了么?
我回答:是的,它会自动找到quartz包中默认的这两个文件,如果你有特殊需要,也可以自己定义这两个文件。
附:quartz.properties
# # Configure Main Scheduler Properties # org.quartz.scheduler.instanceName = TestScheduler org.quartz.scheduler.instanceId = one # # Configure ThreadPool # org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool org.quartz.threadPool.threadCount = 5 org.quartz.threadPool.threadPriority = 4 # # Configure JobStore # #org.quartz.jobStore.misfireThreshold = 5000 #org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore # =========================================================================== # Configure SchedulerPlugins =============================================== # =========================================================================== #org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin #org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy} #org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy} with resulting trigger instruction code: {9} org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin org.quartz.plugin.jobInitializer.fileName =quartz_jobs.xml org.quartz.plugin.jobInitializer.overWriteExistingJobs = false org.quartz.plugin.jobInitializer.failOnFileNotFound = true org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin org.quartz.plugin.shutdownhook.cleanShutdown = true
系统会根据配置文件找到quartz_jobs.xml
我转载的 有什么不明白得地方敬请访问
iLife's 博客http://blog.csdn.net/fei1502816
相关文章推荐
- Quartz+Spring实例应用【一】基于Spring的MethodInvokingJobDetailFactoryBean实现
- spring quartz在项目中的应用实例
- Quartz+spring实例应用
- Quartz+spring实例应用(受教育其他博主的文章,在原来基础之上进行改正)
- Quartz+spring实例应用
- 【Quartz】Spring3.2.9+Quqrtz2.2.1实现定时实例
- Spring整合ActiveMQ与Quartz的实例
- Spring结合java Quartz配置实例代码
- Spring + mybatis整合方案总结 结合实例应用
- 关于Spring-JPA框架下使用多表查询的应用实例记录
- spring多数据源的处理 mybatis实现跨库查询 实现Myibatis动态sql跨数据库的处理 Spring动态配置多数据源,即在大型应用中对数据进行切分,并且采用多个数据库实例进行管理,这样
- Spring - Java/J2EE Application Framework 应用框架 第 18 章 使用Quartz或Timer完成时序调度工作
- java计划任务调度框架quartz结合spring实现调度的配置实例代码
- Spring整合Quartz定时任务 在集群、分布式系统中的应用
- Spring结合java Quartz配置实例代码
- struts2整合 spring应用实例
- 完美解决多应用服务器负载均衡环境下spring quartz同一定时任务重复执行问题
- Java RMI 介绍和例子以及Spring对RMI支持的实际应用实例
- struts2整合 spring应用实例
- Quartz和Spring Task定时任务的简单应用和比较