【发布时间】:2015-11-28 03:52:57
【问题描述】:
背景: 我们有一些由cron作业触发的spring批处理(作为启动应用程序)管理的作业,我正在努力用quartz替换cron并添加spring批处理管理员来管理作业。
到目前为止,我可以通过 spring 批处理管理控制台运行作业,当石英尝试触发作业执行时会出现问题。 JobLauncher、JobLocator 对象为空,它是自动装配的。请注意,我使用基于 Java 的配置而不是 XML。
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
@Component
@EnableBatchProcessing
public class GatewayReconciliationQuartzJob extends QuartzJobBean {
private static final String JOB_NAME = "GatewayReconciliationJob";
@Autowired
BatchJobLauncher batchJobLauncher;
@Autowired
private JobLocator jobLocator;
@Autowired
private JobLauncher jobLauncher;
@Override
protected void executeInternal(JobExecutionContext context) {
try {
if (null == jobLauncher) {
LOG.info("JobLauncher is null ");
}
if (null == jobLocator) {
LOG.info("jobLocator is null ");
}
LOG.info(String.format("Now really Starting Batch Job : %s", JOB_NAME));
JobParametersBuilder builder = new JobParametersBuilder();
builder.addDate("date", new Date());
this.jobLauncher.run(this.jobLocator.getJob(JOB_NAME), builder.toJobParameters());
} catch (JobExecutionAlreadyRunningException | JobInstanceAlreadyCompleteException | JobParametersInvalidException | NoSuchJobException | JobRestartException e) {
LOG.error("Error executing job", e);
throw new RuntimeException(e);
}
}
}
【问题讨论】:
标签: spring quartz-scheduler spring-batch-admin