spring中使用Quartz完成时序调度工作

1、需要jar  quartz-1.6.5.jar\jta_101.jar

2、创建application-schedule.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
	<!--  自定义对象-->
       <bean id="uploadXmlScheduler" class="self.phoenix.application.internal.UploadXmlScheduler">
		<property name="uploadService" ref="uploadService"/>
	</bean>
       <!-- 利用MethodInvokingJobDetailFactoryBean将调用uploadXmlScheduler中的uploadXmlController方法-->
	<bean id="myJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
       <property name="targetObject" ref="uploadXmlScheduler" />
       <property name="targetMethod" value="uploadXmlController" />
       <!-- 使jobs不并发运行-->
       <property name="concurrent" value="false" />
    </bean>
    <!-- Spring提供两个子类triggers: SimpleTriggerBean,CronTriggerBean -->
    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
       <property name="jobDetail" ref="myJobDetail" />
       <!-- wait 10 seconds before starting repeated execution -->
       <property name="startDelay" value="10000" />
       <!-- run every 60 seconds *10 -->
       <property name="repeatInterval" value="600000" />
    </bean>
    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
       <property name="jobDetail" ref="myJobDetail" />
		<!-- run every morning at 23:59 am -->
       <property name="cronExpression" value="0 59 23 * * ?" /> 
    </bean>
    <!--  调用两个触发器 -->
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
       <property name="triggers">
             <list>
               <ref bean="simpleTrigger"/>
               <ref bean="cronTrigger"/>
             </list>
		</property>
    </bean>
    <!-- 注入所需的bean -->
    <bean name="uploadService" class="self.phoenix.application.internal.dao.UploadServiceImpl" />
</beans>

3、创建 定时调用的类 UploadXmlScheduler.java

public class UploadXmlScheduler {

	private UploadService uploadService;

	public void setUploadService(UploadService uploadService) {
		this.uploadService = uploadService;
	}
	
	public void uploadXmlController(){
               /** 执行操作 **/
		uploadService.uploadXml();
	}

	
}
 

你可能感兴趣的:(DAO,spring,工作,bean,quartz)