使用xml配置Quartz,实现定时任务
2017-12-12 11:00
736 查看
使用xml配置Quartz,实现定时任务
使用xml配置前景以前我是使用java代码配置Quartz任务的,到最好你会发现,这个类使用其他类成员变量会无法自动注入问题
始终是空指针问题,到最后只能手动到SpingContext中去取,这样过程很繁琐,不易于管理其他类成员变量
引入Maven依赖
<!-- quartz start --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz-jobs</artifactId> <version>2.2.1</version> </dependency> <!-- quartz end -->
在Spring.xml导入spring-quartz.xml配置
<import resource="spring-quartz.xml" />
在spring-quartz.xml配置Quartz
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-lazy-init="false"> <!--配置任务类,也就是下面targetMethod所在的类--> <bean id="myJob" class="com.founder.isp.fpay.tecsun.quartz.SycTecsunBalance" /> <!-- 配置job --> <bean id="myJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="myJob" /> </property> <property name="targetMethod"> <value>work</value> </property> </bean> <!-- 配置触发器 --> <bean id="crontestJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail"> <ref bean="myJobDetail" /> </property> <property name="cronExpression"> <value>0 * 23 * * ?</value> </property> </bean> <bean name="schedulerFactoryBean" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="crontestJobTrigger" /> </list> </property> </bean> </beans>
相关文章推荐
- 使用Java并发包线程池和XML实现定时任务动态配置和管理
- 在Grails中使用Quartz插件实现定时任务
- Spring+Quartz实现定时任务的配置方法
- 简单介绍Spring+Quartz实现定时任务的配置方法
- Spring+Quartz实现定时任务的配置方法
- spring使用Quartz实现定时任务
- Quartz.Net的使用(简单配置方法)定时任务框架
- Spring+Quartz实现定时任务的配置方法
- Spring中使用quartz插件实现定时任务
- Spring+Quartz实现定时任务的配置实例
- 使用Quartz实现比Timer更强大的任务定时
- Spring3.0.6+Quartz1.8.5实现定时任务的配置方法
- 使用Quartz.Net框架实现定时任务
- Quartz.Net的使用(简单配置方法)定时任务框架
- Spring+Quartz实现定时任务的配置方法
- Spring+Quartz实现定时任务的配置方法
- Spring+Quartz实现定时任务的配置方法
- Spring+Quartz实现定时任务的配置方法
- Spring+Quartz实现定时任务的配置方法
- Spring+Quartz实现定时任务的配置方法