applicationContext.xml 配置:
<!-- 定时服务配置开始 -->
<import resource="classpath:/config/spring/quartz_jobs.xml"/>
quartz_jobs.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 要调用的工作类 -->
<!--
<bean id="startQuartz" class="com.sides.news.StartQuartz"> <property
name="newsRssServiceBiz"> <ref bean="newsRssServiceBiz"/> </property>
</bean>
-->
<!-- 定义调用对象和调用对象的方法 -->
<bean id="newsWeather_jobtask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="weatherServiceBiz" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>startWeather</value>
</property>
</bean>
<!-- 定义触发时间 -->
<bean id="newsWeatherTimer" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="newsWeather_jobtask" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0 1 8,12,18 * * ?</value>
</property>
</bean>
<!-- 定义调用对象和调用对象的方法 -->
<bean id="newsWeather_backtask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="weatherServiceBiz" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>backupData</value>
</property>
</bean>
<!-- 定义触发备份数据 -->
<bean id="newsWeatherBackupTimer" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="newsWeather_backtask" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0 1 2 * * ?</value>
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="newsWeatherTimer" />
<ref bean="newsWeatherBackupTimer" />
</list>
</property>
</bean>
</beans>