参考:http://blog.csdn.net/lk_blog/article/details/11744621
依赖:
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<project xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0
.
0
</modelVersion>
<groupId>com.heli</groupId>
<artifactId>test-quartz</artifactId>
<packaging>war</packaging>
<version>
0.0
.
1
-SNAPSHOT</version>
<name>test-quartz Maven Webapp</name>
<url>http:
//maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-
8
</project.build.sourceEncoding>
<spring.version>
4.1
.
6
.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>
2.2
.
1
</version>
</dependency>
<!-- servlet
3
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>
3.0
.
1
</version>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
|
配置:
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
40
41
42
43
44
|
<?xml version=
"1.0"
encoding=
"UTF-8"
?>
<beans xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:p=
"http://www.springframework.org/schema/p"
xsi:schemaLocation="http:
//www.springframework.org/schema/beans
http:
//www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- 启动触发器的配置开始 -->
<bean name=
"startQuertz"
lazy-init=
"false"
autowire=
"no"
class
=
"org.springframework.scheduling.quartz.SchedulerFactoryBean"
>
<property name=
"triggers"
>
<list>
<ref bean=
"myJobTrigger"
/>
</list>
</property>
</bean>
<!-- 启动触发器的配置结束 -->
<!-- quartz-
2
.x的配置 -->
<bean id=
"myJobTrigger"
class
=
"org.springframework.scheduling.quartz.CronTriggerFactoryBean"
>
<property name=
"jobDetail"
>
<ref bean=
"myJobDetail"
/>
</property>
<property name=
"cronExpression"
>
<!--middle night
24
.
do
it -->
<value>
0
0
0
* * ?</value>
</property>
</bean>
<!-- 调度的配置结束 -->
<!-- job的配置开始 -->
<bean id=
"myJobDetail"
class
=
"org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
>
<property name=
"targetObject"
>
<ref bean=
"myJob"
/>
</property>
<property name=
"targetMethod"
>
<value>work</value>
</property>
</bean>
<!-- job的配置结束 -->
<!-- 工作的bean -->
<bean id=
"myJob"
class
=
" com.heli.job.MyJob"
/>
</beans>
|
类:
1
2
3
4
5
6
7
8
9
10
|
package
com.heli.job;
import
java.util.Date;
public
class
MyJob {
public
void
work() {
System.out.println(
"date:"
+
new
Date().toString());
}
}
|