spring配置quartz:定时去执行一个方法

来源:互联网 发布:ipad淘宝没有免费试用 编辑:程序博客网 时间:2024/05/29 19:21

参考文章:http://www.jb51.net/article/107339.htm


1,其中加注释的地方是自己要修改的,其他的代码都不可以不动,当然你也可以把id什么的改成自己想要的。项目启动时你想要的方法就会自动执行了。

2,这中配置对版本有些要求,具体参考上面的文章。


<?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.xsd">

  <bean id="sceneDao" class="com.surekam.collie.scene.dao.impl.SceneDaoImpl">  //自己的Dao    <property name="sessionFactory" ref="sessionFactory"/>    <property name="jdbcBaseDAO" ref="jdbcBaseDAO"/>  </bean>    <bean id="sceneService" class="com.surekam.collie.scene.service.impl.SceneServiceImpl"> //自己的service    <property name="sceneDao" ref="sceneDao"/>    </bean>    <bean id="backupJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">    <property name="targetObject">    <ref bean="sceneService"/>             //引入上面自己的service    </property>    <property name="targetMethod">    <!--<value>getDatasByClass</value>-->        <value>textQuartz</value>              //textQuartz是service中要执行的方法,写自己的方法    </property>    </bean>    <bean id="backupCronEventTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">    <property name="jobDetail">    <ref bean="backupJobDetail"/>    </property>    <property name="cronExpression">    <!--每5s执行一次-->    <value>* 0/5 * * * ?</value>         //cron表达式,设置多长时间执行一次    <!--12点执行一次-->    <!--<value>0 0 12 * * ?</value>-->    </property>    </bean>    <bean id="backupStrategy" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">    <property name="triggers">    <list>    <ref bean="backupCronEventTrigger"/>    </list>    </property>    </bean>
</beans>


原创粉丝点击