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