1. vo를 통하여 선태된 JobExecution Id선택
String jobExecutionId = vo.getJOB_EXECUTION_ID();
this.logger.debug(" jobExecutionId " + jobExecutionId);
2. ApplicationContext 설정하기
ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
new String[] { "simple-job-launcher-context.xml", "jobs/ CF_EI10000Job.xml", "jobs/DD20101BJob.xml" });
3. ApplicationContext 에서 operator 가져오기
SimpleJobOperator oper = (SimpleJobOperator)classPathXmlApplicationContext.getBean("jobOperator");
4. ApplicationContext에서 Job가져오기
Job job = (Job) classPathXmlApplicationContext.getBean ("CF_EI10000");
Job DD20101B = (Job) classPathXmlApplicationContext.getBean ("DD20101B");
5. job을 이용하여 잡팩토리 생성
ReferenceJobFactory jobfactory = new ReferenceJobFactory(job);
ReferenceJobFactory DD20101Bjobfactory = new ReferenceJobFactory (DD20101B);
ListableJobRegistry jobRegistry = new MapJobRegistry();
try {
/* registry에 잡팩토리 등록 */
jobRegistry.register(DD20101Bjobfactory);
jobRegistry.register(jobfactory);
Or
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<bean id="jobRegitry" class="....MapJobRegistry">
이 선언만 들어와 있으면 applicationContext올라가면서 자동으로 jobRegitry에 Job들이 등록된다.
/* operator 에 JobRegistry 등록 */
oper.setJobRegistry(jobRegistry);
/* operator 를 이용하여 잡 실행 */
oper.restart(Long.parseLong(jobExecutionId));
6. JobRegistryBeanPostProcessor를 이용해 MapJobRepository를 초기화하는 방법
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
ClassPathXmlJobRegitry를 쓰면 기본적으로 Job interface를 구현한 모든 bean들을 등록해준다.. MapJobRegitry는 따로 등록절차 거쳐서 job을 관리할 필요가 있을 때 사용.
7. Operator 예제 소스
ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
new String[] { "simple-job-launcher-context.xml", "jobs/CF_EI10000Job.xml" });
SimpleJobOperator oper = (SimpleJobOperator) classPathXmlApplicationContext.getBean("jobOperator");
JobParametersBuilder builder = new JobParametersBuilder();
builder.addString("CORP_SECD", "TI01");
builder.addString("PROC_STD_YMD", "20090831");
builder.addDate("START_TIME", new Date());
builder.toJobParameters();
oper.start("CF_EI10000", builder.toString());