一:创建定时任务执行的类
public class quartzJob {
/** 日志 */
private static Log log = LogFactory.getLog(quartzJob.class);
public void work() throws Exception {
try {
log.error("----------------------->定时下载解析影像资料开始------------->");
log.error("----------------------->定时下载解析影像资料结束------------->");
} catch (Exception e) {
log.error(e.getMessage());
throw new Exception(e.getMessage(),e);
}
}
}
|
二:指定目录下创建springquartz配置文件SpringQuartzJob.xml(文件名自定义)
<?xml version="1.0" encoding="GB2312"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- ###################################################### spring 高级job #########################-->
<!-- 总调度,用于启动定时器 -->
<bean id="schedulerFactory"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="SyncDataTask" />
</list>
</property>
</bean>
<!--1 配置一个触发器 -->
<bean id="SyncDataTask" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="SyncDataJobTask"></property>
<!-- 1:秒 2:分3:小时4:月份中的日期(1-31)5:月份(1-12或JAN-DEC)6:星期中的日期(1-7或SUN-SAT)7:年份(1970-2099) -->
<property name="cronExpression" value="0 */1 * * * ?"></property> <!--0 */20 * * * ?=======0 30 23 * * ?-->
</bean>
<!--2 配置需要定时的bean类 -->
<bean id="SyncDataJob" class="cn.gov.pbc.mimis.quartz.quartzJob"></bean>
<!--3 配置任务的具体类和方法 -->
<bean id="SyncDataJobTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 要调用的bean -->
<property name="targetObject" ref="SyncDataJob"></property>
<!-- 要调用的Method -->
<property name="targetMethod" value="work"></property>
<!-- 是否并发,false表示 如果发生错误也不影响下一次的调用 -->
<property name="concurrent" value="false"></property>
</bean>
</beans>
|
三:web.xml里面配置要加载的quartz配置文件
/WEB-INF/classes/config/quartz/SpringQuartzJob.xml, |