[java] Spring 스케줄러, QuartzJobBean
1. 클래스 작성
package com.jw.customized.sync;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.jw.customized.migration.DeptMigration;
public class SyncJob extends QuartzJobBean implements StatefulJob {
private static final Log logger = LogFactory.getLog(SyncJob.class);
private DeptMigration deptMigration = null;
public DeptMigration getDeptMigration() {
return deptMigration;
}
public void setDeptMigration(DeptMigration deptMigration) {
this.deptMigration = deptMigration;
}
@Override
protected void executeInternal(JobExecutionContext jobexecutioncontext)
throws JobExecutionException {
if (this.deptMigration != null) {
if (this.deptMigration.isDoingExecute()) {
logger.warn("실행중입니다.");
} else {
this.deptMigration.execute();
}
}
}
}
2. xml에 설정하고 Quartz 설정
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans default-init-method="initialize">
.....
.....
<bean id="migration.DeptMigration" class="com.jw.customized.migration.DeptMigration">
<property name="dbConnectionManager"><ref bean="datasource.DBConnectionManager" /></property>
</bean>