Showing
1 changed file
with
0 additions
and
87 deletions
技术分享/springquartz.md
deleted
100644 → 0
1 | -spring集成quartz | ||
2 | -注意:出现异常“Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class” | ||
3 | -Spring3.0不支持Quartz2.0,因为org.quartz.CronTrigger在2.0从class变成了一个interface造成IncompatibleClassChangeError错误: | ||
4 | - | ||
5 | -有两种办法: | ||
6 | -第一种降低quartz的版本为,最好是quartz1.8 | ||
7 | -第二种是升级spring版本为Spring3.2以上 | ||
8 | -注:Spring3.2.4配置文件中使用CronTriggerFactoryBean来集成quartz2.x, | ||
9 | - 使用CronTriggerBean来集成quartz1.8.x及以前版本. | ||
10 | - | ||
11 | -以下是一个小例子demo | ||
12 | -<!-- 启动触发器的配置开始 --> | ||
13 | - <bean name="startQuertz" lazy-init="false" autowire="no" | ||
14 | - class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> | ||
15 | - <property name="triggers"> | ||
16 | - <list> | ||
17 | - <ref bean="myJobTrigger" /> | ||
18 | - </list> | ||
19 | - </property> | ||
20 | - </bean> | ||
21 | - <!-- 启动触发器的配置结束 --> | ||
22 | - | ||
23 | - <!-- 调度的配置开始 --> | ||
24 | - <!-- | ||
25 | - quartz-1.8以前的配置 | ||
26 | - <bean id="myJobTrigger" | ||
27 | - class="org.springframework.scheduling.quartz.CronTriggerBean"> | ||
28 | - <property name="jobDetail"> | ||
29 | - <ref bean="myJobDetail" /> | ||
30 | - </property> | ||
31 | - <property name="cronExpression"> | ||
32 | - <value>0/1 * * * * ?</value> | ||
33 | - </property> | ||
34 | - </bean> | ||
35 | - --> | ||
36 | - <!-- quartz-2.x的配置 --> | ||
37 | - <bean id="myJobTrigger" | ||
38 | - class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> | ||
39 | - <property name="jobDetail"> | ||
40 | - <ref bean="myJobDetail" /> | ||
41 | - </property> | ||
42 | - <property name="cronExpression"> | ||
43 | - <value>0/1 * * * * ?</value> | ||
44 | - </property> | ||
45 | - </bean> | ||
46 | - <!-- 调度的配置结束 --> | ||
47 | - | ||
48 | - <!-- job的配置开始 --> | ||
49 | - <bean id="myJobDetail" | ||
50 | - class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> | ||
51 | - <property name="targetObject"> | ||
52 | - <ref bean="myJob" /> | ||
53 | - </property> | ||
54 | - <property name="targetMethod"> | ||
55 | - <value>work</value> | ||
56 | - </property> | ||
57 | - </bean> | ||
58 | - <!-- job的配置结束 --> | ||
59 | - | ||
60 | - <!-- 工作的bean --> | ||
61 | - <bean id="myJob" class="com.tgb.lk.demo.quartz.MyJob" /> | ||
62 | - | ||
63 | - | ||
64 | - | ||
65 | -package com.demo.test; | ||
66 | - | ||
67 | - | ||
68 | -import java.util.Date; | ||
69 | - | ||
70 | - | ||
71 | -/* | ||
72 | - * 使用spring+Quartz执行任务调度的具体类 | ||
73 | - * */ | ||
74 | -public class MyJob { | ||
75 | - | ||
76 | - | ||
77 | - /* | ||
78 | - * Description:具体工作的方法,此方法只是向控制台输出当前时间, | ||
79 | - * 输入的日志在:%tomcatRoot%\logs\tomcat7-stdout.yyyy-MM-dd.log中, | ||
80 | - * 其中,yyyy-MM-dd为部署的日期,经试验发现默认情况下并不是每天都生成一个stdout的日志文件 | ||
81 | - * @return 返回void | ||
82 | - * */ | ||
83 | - public void work() | ||
84 | - { | ||
85 | - System.out.println("当前时间:"+new Date().toString()); | ||
86 | - } | ||
87 | -} |
-
Please register or login to post a comment