【问题标题】:Quartz scheduler not working in Spring batch admin setupQuartz 调度程序在 Spring 批处理管理设置中不起作用
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-10
      • 1970-01-01
      • 2022-07-19
      • 2011-08-03
      • 2020-12-29
      • 2017-04-24
      • 1970-01-01
      • 2019-09-22
      相关资源
      最近更新 更多