其实配置spring的定时器很简单,看下面配置:
<!--实际的工作Bean-->
<bean id="importData" class="com.eshore.transdata.timerjob.ImportData" lazy-init="false">
</bean>
<!--jobBean用于设定启动时运用的Bean与方法-->
<bean id="scheduledReportJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" lazy-init="false">
<property name="targetObject">
<ref bean="importData" />
</property>
<property name="targetMethod" value="run">
</property>
</bean>
<!--定时器设定每天6点运行-->
<bean id="cronReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean" lazy-init="false">
<property name="jobDetail">
<ref bean="scheduledReportJobDetail" />
</property>
<property name="cronExpression">
<value>0 0 6 * * ?</value>
</property>
</bean>
<bean id="quartzSchedule" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
<property name="triggers">
<list>
<ref bean="cronReportTrigger" />
</list>
</property>
</bean>
其中<value>0 0 6 * * ?</value> 表示每天6点正式启动运行你想要运行的内容。如果你要每月多少号进行的话应改为:<value>0 M * * * ?</value> 其中M是你要填写的每月的第几天。就这样简单! 搞定。你们呢?
来源:oschina
链接:https://my.oschina.net/u/855150/blog/84538