I am trying to make use of Spring batch to deal with batch jobs.
When I try to stop a running job using executionId, the job is stopped with below entry in SpringBatchDb.BATCH_JOB_EXECUTION table
'104','3','104','2017-11-27 11:39:10','2017-11-27 11:39:10','2017-11-27 11:39:48','STOPPED','STOPPED','org.springframework.batch.core.JobInterruptedException','2017-11-27 11:39:48',NULL
Note that the STATUS and EXIT_CODE is updated as STOPPED. But it throws an exception as, org.springframework.batch.core.launch.NoSuchJobException: No job configuration with the name [testJob] was registered
at org.springframework.batch.core.configuration.support.MapJobRegistry.getJob(MapJobRegistry.java:66)
at org.springframework.batch.core.launch.support.SimpleJobOperator.restart(SimpleJobOperator.java:275)
at org.springframework.batch.core.launch.support.SimpleJobOperator$$FastClassBySpringCGLIB$$44ee6049.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:669)
at org.springframework.batch.core.launch.support.SimpleJobOperator$$EnhancerBySpringCGLIB$$318ff269.restart(<generated>)
at com.test.mypackage.batch.dao.BatchJobDaoImpl.restartJobExecution(BatchJobDaoImpl.java:62) .
When I attempt to restart the same job using executionId, it fails to start and gives same exception (shown above).
My Code is pretty simple,
@Autowired
private DataSource dataSource;
@Autowired
private JobOperator jobOperator;
@Override
public Long stopRunningExecution(Long executionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException {
jobOperator.stop(executionId);
return executionId;
}
@Override
public Long restartJobExecution(long executionId) throws JobParametersInvalidException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException {
return jobOperator.restart(executionId);
}
Whats wrong here?