spring-bootspring-batchbatch-processingspring-batch-integration

Spring batch job restart after server crash fails as job registry does not contain job after upgrade to spring batch core jar to 5.12


Spring batch partition job which would have been in STARTED status due to server crash. Now if we change the status of both job execution and stop from STARTED to FAILED and call jobOperator.restart(failedBatchExecutionId); it used to restart the same and process pending data.

For that we had used,

@bean(name = "febpBatchJobRegistry")
public JobRegistry jobRegistry() throws Exception {
return new MapJobRegistry();
}

@bean
public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(@qualifier("febpBatchJobRegistry") JobRegistry jobRegistry) {
JobRegistryBeanPostProcessor postProcessor = new JobRegistryBeanPostProcessor();
postProcessor.setJobRegistry(jobRegistry);
return postProcessor;
}

@bean(name = "febpBatchJobOperator")
public JobOperator jobOperator(@qualifier("febpBatchJobLauncher") JobLauncher jobLauncher, @qualifier("febpBatchJobRepository") JobRepository jobRepository,
@qualifier("febpBatchJobRegistry") JobRegistry jobRegistry, @qualifier("febpBatchJobExplorer") JobExplorer jobExplorer) {
final SimpleJobOperator jobOperator = new SimpleJobOperator();
jobOperator.setJobLauncher(jobLauncher);
jobOperator.setJobRepository(jobRepository);
jobOperator.setJobRegistry(jobRegistry);
jobOperator.setJobExplorer(jobExplorer);
return jobOperator;
}

But now with upgrade to 5.12 we are facing org.springframework.batch.core.launch.NoSuchJobException: No job configuration with the name [FEBP_EMP_TAX_CALCULATION] was registered at org.springframework.batch.core.configuration.support.MapJobRegistry.getJob(MapJobRegistry.java:68)


Solution

  • Try to change JobRegistryBeanPostProcessor with a JobRegistrySmartInitializingSingleton which was introduced in v5.1.1. This should fix your issue.

    @Bean
    public JobRegistrySmartInitializingSingleton jobRegistrySmartInitializingSingleton(@qualifier("febpBatchJobRegistry") JobRegistry jobRegistry) {
        return new JobRegistrySmartInitializingSingleton(jobRegistry);
    }