quartz定时任务在springmvc中的配置

quartz可以独立配置xml文件,也可以直接写在spring的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"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    					http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    					http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    					http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    					http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
						http://www.springframework.org/schema/util	http://www.springframework.org/schema/util/spring-util-3.1.xsd
						http://www.springframework.org/schema/jee	http://www.springframework.org/schema/jee/spring-jee-3.0.xsd" >
	<context:annotation-config />
	<context:component-scan base-package="com.canon" />
	
	<jee:jndi-lookup id="dataSource" jndi-name="jdbc/db"/>
	
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
    </bean>
	
	<!-- 1.增加一个线程池:线程执行器配置,用于任务注册 -->
	<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
	 <property name="corePoolSize" value="10" />
	 <property name="maxPoolSize" value="20" />
	 <property name="queueCapacity" value="100" />
	</bean>

	<!-- a.加入需要执行的类 -->
	<bean id="doBatch" class="com.canon.cits.batch.BatchSchedule"></bean>
	<!-- b.加入定时执行的方法 -->
	<bean id="synDupdateMapInfoBatch" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
	  <!-- c.定时执行的类 -->
	  <property name="targetObject" ref="doBatch"/>
	  <!-- d.具体的方法  -->
	  <property name="targetMethod" value="updateMapInfo"/>
	  <property name="concurrent" value="false"/>
	</bean>
	<!-- e.增加调度触发器,设置自己想要的时间 -->
	<bean id="synDupdateMapInfoTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		 <!-- 加入相关的执行类和方法 -->
	  <property name="jobDetail" ref="synDupdateMapInfoBatch"/>
	   <!-- 设置时间规则 (一分钟一次)-->
	  <property name="cronExpression">
		<value>00 * * * * ?</value>
	  </property>
	</bean>
	<!-- 配置项目启动后任务就执行一次 -->  
    <bean id="synDupdateMapInfoTrigger1" class="org.springframework.scheduling.quartz.SimpleTriggerBean">  
        <property name="jobDetail" ref="synDupdateMapInfoBatch" />  
        <property name="startDelay" value="500" />  
        <property name="repeatInterval" value="0" />  
        <property name="repeatCount" value="0" />  
    </bean>  
    	
	<!-- 5、增加调度 -->
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
	  <property name="triggers">
	   <list>
	        <ref local="synDupdateMapInfoTrigger"/>
	   </list>
	  </property>
	  <property name="taskExecutor" ref="executor"/>
	</bean>	
</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值