Spring定时机制
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" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>startWeather</value>
</property>
</bean>
?
<!-- 定义触发时间 -->
<bean id="newsWeatherTimer" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0 1 8,12,18 * * ?</value>
</property>
</bean>
?
<!-- 定义调用对象和调用对象的方法 -->
<bean id="newsWeather_backtask"
/>
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>backupData</value>
</property>
</bean>
<!-- 定义触发备份数据 -->
<bean id="newsWeatherBackupTimer" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0 1 2 * * ?</value>
</property>
</bean>
?
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 ?-->
<bean id="startQuertz" lazy-init="false" autowire="no"
/>
<ref bean="newsWeatherBackupTimer" />
</list>
</property>
</bean>
?
</beans>
?