Spring框架的定时器的配置及使用



applicationContext-quartz.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<!-- PublicHousing page daily report, added by Cong 2016-10-19 -->
        <!--定义任务--> 
	<bean id="publichousingDailyReportJob“
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject">
       <!--指定要定时执行的方法所在类,将定时任务定义成bean-->		                 <ref bean="PublicHousingDailyReportService" />
		</property>
		<property name="targetMethod">
        <!--定义任务执行的方法-->
			<value>sendReport</value>
		</property>
	</bean>
	<bean id="publichousingDailyReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail">
			<ref bean="publichousingDailyReportJob"/>
		</property>
        <!--指定重复间隔的定时任务-->
		<property name="cronExpression">
			<!-- [秒] [分] [小时] [日] [月] [周] [年] -->
			<value>0 0 13 * * ?</value>
		</property>
	</bean>
	<!-- PublicHousing page daily report end -->

	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<!--此处需要开启,调度任务-->
				<!--<ref local="lesportsHalfDailyReportTrigger"/> 
			        <ref local="publichousingDailyReportTrigger" />
			</list>
		</property>
	</bean>
</beans>


applicationContext-service.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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
            http://www.springframework.org/schema/tx <a target=_blank href="http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">http://www.springframework.org/schema/tx/spring-tx-2.0.xsd</a>"
	default-lazy-init="true">

	<bean id="PublicHousingDailyReportService" class="com.hthk.iisz.service.PublicHousingDailyReportService" />
	
</beans>

最后在web.xml中填写配置文件的地址和类加载监听器

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>RBS</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
  		/WEB-INF/classes/applicationContext-*.xml
  	</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

</web-app>
可参考链接: http://jingyan.baidu.com/article/0f5fb099cc244d6d8234ea6b.html




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值