参考文章:http://www.jb51.net/article/107339.htm
1,其中加注释的地方是自己要修改的,其他的代码都不可以不动,当然你也可以把id什么的改成自己想要的。项目启动时你想要的方法就会自动执行了。
2,这中配置对版本有些要求,具体参考上面的文章。
<?xml version="1.0" encoding="UTF-8"?>
复制代码
1
2
3
4
5<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">
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39<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>
复制代码
1
2
3复制代码</beans>
复制代码
最后
以上就是腼腆朋友最近收集整理的关于spring配置quartz:定时去执行一个方法的全部内容,更多相关spring配置quartz内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复