通過maven添加Quartz
pom.xml中相關dependency信息
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.5</version>
</dependency>
quartzJob.xml
<!-- 定義目標bean和bean中的方法 -->
<!-- =====================日常任務job========================== -->
<bean id="DailyTaskQtzJob" class="com.test.quartz.DailyTaskJob">
</bean>
<bean id="DailyTaskQtzJobMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="DailyTaskQtzJob"/>
</property>
<property name="targetMethod"> <!-- 要執行的方法名稱 -->
<value>execute</value>
</property>
</bean>
<!-- ======================== 調度觸發器 ======================== -->
<bean id="DailyTaskCronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="DailyTaskQtzJobMethod"></property>
<!-- 每天下午16:30觸發 -->
<property name="cronExpression" value="0 30 16 ? * *"></property>
</bean>
<!-- ======================== 調度工廠 ======================== -->
<bean id="SpringJobSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="DailyTaskCronTriggerBean"/>
</list>
</property>
</bean>
DailyTaskJob.java
package com.test.quartz;
public class DailyTaskJob {
protected void execute() {
//執行任務
}
}
最後在web.xml中添加quartzJob.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/beans.xml
WEB-INF/quartz/quartzJob.xml
</param-value>
</context-param>
OK,這就配好啦,記錄一下,防止以後忘了。