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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="false">
<!-- task -->
<!-- 定义了一个任务 -->
<bean id="quartzClock" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.operateportals.framework.quartz.job.DataTimingJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="tellerFile" value="1" />
<entry key="deleteTellerFile" value="2" />
<entry key="orgFile" value="3" />
</map>
</property>
</bean>
<!-- 这种配置可以精确几点执行定时任务 -->
<!-- 定义了任务的执行方式 -->
<bean id="cronQuartzClock" class="org.springframework.scheduling.quartz.CronTriggerBean" >
<property name="jobDetail">
<ref bean="quartzClock"></ref>
</property>
<property name="cronExpression">
<value>0 0/1 * * * ?</value>
</property>
</bean>
<!--第三步 启动定时任务,注意这里的ref bean -->
<bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronQuartzClock"></ref>
</list>
</property>
<property name="waitForJobsToCompleteOnShutdown" value="true"/>
</bean>
</beans>
java文件
package com.operateportals.framework.quartz.job;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.operateportals.applications.comm.securitymanage.auth.base.constans.SysUserConstants;
import com.operateportals.applications.comm.securitymanage.auth.entity.dao.orginfodao.OrgInfo;
import com.operateportals.applications.comm.securitymanage.auth.entity.dao.sysuserdao.SysUser;
import com.operateportals.applications.comm.securitymanage.usermanage.service.ISysUserInfoService;
import com.operateportals.applications.comm.securitymanage.usermanage.service.IUserOrgInfoService;
import com.operateportals.framework.util.ApplicationContextUtil;
import com.operateportals.framework.util.UtilValidate;
public class DataTimingJob extends QuartzJobBean{
private static final Log logger = LogFactory.getLog(DataTimingJob.class);
public DataTimingJob() {
super();
}
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext)
throws JobExecutionException {
logger.info("DataTimingJob start!");
try {
JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
String tellerFile = jobDataMap.getString("tellerFile");
String deleteTellerFile = jobDataMap.getString("deleteTellerFile");
String orgFile = jobDataMap.getString("orgFile");
System.out.println(tellerFile);
System.out.println(deleteTellerFile);
System.out.println(orgFile);
} catch (Exception e) {
logger.error("DataTimingJob exception," + e);
}
}
}