spring整合quartz实现任务的定时调度:
spring的配置文件如下:除了spring 的核心jar包之外还需要:spring-context-support.jar
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<bean id="springContext" class="com.supermap.base.core.SuperSpringContext"></bean>
<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:config.properties" />
<!-- 要调用的工作类(quartzJob是com.kay.quartz.QuartzJob的实例化) -->
<bean id="quartzJob" class="com.supermap.jointclient.task.Test"></bean>
<!-- 定义调用对象和调用对象的方法 -->
<bean id="jobtask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类(targetObject是固定写法,quartzJob是要调用的对象) -->
<property name="targetObject">
<ref bean="quartzJob" />
</property>
<!-- 调用类中的方法(targetMethod是固定写法,work是要调用的方法) -->
<property name="targetMethod">
<value>execute</value>
</property>
<property name="arguments" value="${XZQHDM}"/>
</bean>
<!-- 定义触发时间 -->
<bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<!-- 需要定时调度的任务(jobtask为调度工厂) -->
<property name="jobDetail">
<ref bean="jobtask" />
</property>
<!-- cron表达式,从第10秒开始执行,每5秒执行一次 -->
<property name="cronExpression">
<value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value>
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false" autowire="default"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<!-- 触发需要执行的时间计划 -->
<property name="triggers">
<list>
<ref bean="doTime" />
</list>
</property>
</bean>
</beans>
以上配置文件配置好之后:需要编写对应的java的quartz调度的类,在类中的方法中实现定时的业务逻辑。需要注意的是,索要执行的方法中有参数可以通过增加如下配置进行参数的传递: <property name="arguments" value="${XZQHDM}"/>