背景: 我们有一些由cron job触发的spring batch(作为启动应用程序)管理的作业,我正在努力用石英替换cron并添加spring batch admin来管理作业。
到目前为止,我能够通过spring batch管理控制台运行作业,当quartz尝试触发作业执行时会发生问题。 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);
}
}
}
答案 0 :(得分:0)
来自here:
将以下行添加到executeInternal
方法的开头:
@Override
public void executeInternal(final JobExecutionContext context) throws JobExecutionException {
// Adding this autowires everything as needed
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
...
}