Bug description
We use dynamically defined Spring Batch jobs, i.e., jobs defined dynamically via JobBuilder with subsequent jobRegistry.register(Job job), not as Job Spring beans which are loaded upon application startup.
After upgrade to Spring Batch 6, we define JobRegistry as in:
@Bean
JobRegistry springBatchJobRegistry() {
return new MapJobRegistry();
}
to be able to register jobs dynamically because JobRegistry Spring bean is not available from Spring Batch 6 anymore (which is OK).
The problem comes when we try to stop job via jobOperator.stop().
Because JobOperator now has only its own MapJobRegistry created via org.springframework.batch.core.launch.support.JobOperatorFactoryBean#afterPropertiesSet() or via org.springframework.batch.core.configuration.support.DefaultBatchConfiguration#getJobRegistry, the registry has no dynamically job defined, hence JobOperator doesn't call stoppableStep.stop().
Solution could be to check whether a JobRegistry Spring bean is defined before creating MapJobRegistry and use it accordingly.
Currently, to solve the problem, we extended JobOperator, define our custom JobOperator Spring bean and explicitly pass our MapJobRegistry to it.
Environment
Spring Batch 6.0.1, SQL Server 2022
Steps to reproduce
- Defined JobRegistry Spring bean in the app
- Create a job using JobBuilder and the JobRegistry above
- Start the job
- Stop the job using jobOperator bean (available from Spring Batch configuration) - stoppableStep.stop() is not called.
Expected behavior
stoppableStep.stop() is called as part of jobOperator.stop()
Bug description
We use dynamically defined Spring Batch jobs, i.e., jobs defined dynamically via JobBuilder with subsequent jobRegistry.register(Job job), not as Job Spring beans which are loaded upon application startup.
After upgrade to Spring Batch 6, we define JobRegistry as in:
to be able to register jobs dynamically because JobRegistry Spring bean is not available from Spring Batch 6 anymore (which is OK).
The problem comes when we try to stop job via jobOperator.stop().
Because JobOperator now has only its own MapJobRegistry created via
org.springframework.batch.core.launch.support.JobOperatorFactoryBean#afterPropertiesSet()or viaorg.springframework.batch.core.configuration.support.DefaultBatchConfiguration#getJobRegistry, the registry has no dynamically job defined, hence JobOperator doesn't call stoppableStep.stop().Solution could be to check whether a JobRegistry Spring bean is defined before creating MapJobRegistry and use it accordingly.
Currently, to solve the problem, we extended JobOperator, define our custom JobOperator Spring bean and explicitly pass our MapJobRegistry to it.
Environment
Spring Batch 6.0.1, SQL Server 2022
Steps to reproduce
Expected behavior
stoppableStep.stop() is called as part of jobOperator.stop()