Example usage for org.springframework.batch.core.job SimpleJob afterPropertiesSet

List of usage examples for org.springframework.batch.core.job SimpleJob afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.batch.core.job SimpleJob afterPropertiesSet.

Prototype

@Override
public void afterPropertiesSet() throws Exception 

Source Link

Document

Assert mandatory properties: JobRepository .

Usage

From source file:org.springframework.data.hadoop.admin.util.HadoopWorkflowUtils.java

/**
 * create and register Spring Batch job/*w  ww.j a v  a 2 s . com*/
 * 
 * @param context root application context
 * @param artifacts workflow artifacts which include workflow descriptor and class loader information.
 * @throws Exception
 */
public static void createAndRegisterSpringBatchJob(ApplicationContext context,
        final WorkflowArtifacts artifacts) throws SpringHadoopAdminWorkflowException {
    if (context == null) {
        logger.warn("root applicaton context is null");
        throw new SpringHadoopAdminWorkflowException("root applicaton context is null");
    }
    String workflowDescriptor = getWorkflowDescriptor(artifacts);
    logger.info("create spring batch job:" + workflowDescriptor + ", classloader:"
            + artifacts.getWorkflowClassLoader());

    final FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext();
    ctx.setClassLoader(artifacts.getWorkflowClassLoader());
    ctx.setConfigLocation(HadoopWorkflowUtils.fileURLPrefix + workflowDescriptor);

    try {
        SimpleJob job = new SimpleJob(generateSpringBatchJobName(artifacts));
        TaskletStep step = new TaskletStep(springHadoopTaskName);
        SimpleSpringHadoopTasklet tasklet = new SimpleSpringHadoopTasklet();
        tasklet.setContext(ctx);
        step.setTasklet(tasklet);
        JobRepository jobRepository = context.getBean(JobRepository.class);
        DataSourceTransactionManager transactionManager = context.getBean("transactionManager",
                DataSourceTransactionManager.class);
        step.setTransactionManager(transactionManager);
        step.setJobRepository(jobRepository);
        step.afterPropertiesSet();
        job.addStep(step);
        JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class);
        job.setJobRepository(jobRepository);
        job.afterPropertiesSet();
        JobFactory jobFactory = new ReferenceJobFactory(job);
        jobRegistry.register(jobFactory);
    } catch (Exception e) {
        logger.warn("create and register Spring Batch Job failed");
        throw new SpringHadoopAdminWorkflowException("create and register Spring Batch Job failed", e);
    }
}