jar依赖包
quartz-context.xml配置文件
<?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"
xmlns:c="http://www.springframework.org/schema/c" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- ===========================配置Scheduler========================= -->
<!-- 配置SchedulerFactoryBean -->
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="overwriteExistingJobs" value="true" />
<property name="autoStartup" value="true" />
<property name="configLocation" value="classpath:quartz.properties" />
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
<property name="jobFactory">
<bean class="com.aifa.project.nonbank.client.support.ScheduleQuartzJobBeanFactorySupport" />
</property>
<property name="triggers">
<list>
<ref bean="billCreateScheduleCronTrigger" />
</list>
</property>
</bean>
<!-- ===========================配置Scheduler========================= -->
<!-- 账单生成定时任务jobDetail -->
<bean id="billCreateScheduleJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.aifa.project.nonbank.client.schedule.BillCreateSchedule" />
<property name="name" value="billCreateSchedule" />
<property name="durability" value="true" />
</bean>
<!-- 账单生成定时任务任务cronTrigger 每个月的一号一点触发-->
<bean id="billCreateScheduleCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail"><ref bean="billCreateScheduleJobDetail" /></property>
<property name="cronExpression"><value>0 0 1 1 * ?</value></property>
</bean>
</beans>
定时任务触发调用的类
package com.aifa.project.nonbank.client.schedule;
import java.util.Date;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.aifa.core.support.DateSupport;
import com.aifa.core.support.LoggerSupport;
import com.aifa.project.nonbank.core.service.BillGenerationService;
import com.aifa.project.nonbank.core.service.OriginDataElecGovCenterLoaderService;
import com.aifa.project.nonbank.core.service.QueryRecordService;
/**
* 账单生成定时任务
* @author guangwen zhou
*
*/
public class BillCreateSchedule extends QuartzJobBean {
/**
* 日志对象
*/
@Autowired
private LoggerSupport logger;
/**
* 日期支撑类
*/
@Autowired
private DateSupport dateSupport;
/**
* 账单生成服务对象
*/
@Autowired
private BillGenerationService billGenerationService;
@Override
protected void executeInternal(JobExecutionContext arg0)throws JobExecutionException {
logger.debug(">>定时生成账单任务 启动:"+dateSupport.formatCharacter(dateSupport.getSystemDate(),"yyyy-MM-dd HH:mm:ss"));
try {
//这里调用具体的业务方法即可
billGenerationService.createBill();
} catch (Exception e) {
logger.error(">>定时生成申请结果任务异常", e);
}
logger.debug(">>定时生成账单任务 完成:"+dateSupport.formatCharacter(dateSupport.getSystemDate(),"yyyy-MM-dd HH:mm:ss"));
}
}