Quartz 调度程序在 Spring 批处理管理设置中不工作

Quartz scheduler not working in Spring batch admin setup

背景: 我们有一些由 cron 作业触发的 spring 批处理(作为启动应用程序)管理的作业,我正在努力用 quartz 替换 cron 并添加 spring 批处理管理员来管理作业。

到目前为止,我可以通过 spring 批处理管理控制台 运行 作业,当 quartz 尝试触发作业执行时会出现问题。 JobLauncher、JobLocator 对象为 null,这是自动装配的。请注意我使用基于 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);
        }

    }
}

来自here: 将以下行添加到 executeInternal 方法的开头:

@Override
public void executeInternal(final JobExecutionContext context) throws JobExecutionException {
    // Adding this autowires everything as needed
    SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);    
    ...
}