Skip to content
Advertisement

Spring Batch restart persistent jobs after abnormal termination

I have a following Spring Batch Job config:

JavaScript

I’m starting the job with a following code:

JavaScript

This is my test tasklet:

JavaScript

I use H2 database as a persistent storage for my jobs.

During the jobs execution I’m terminating my application. Right after application restart I expect that all uncompleted jobs will continue execution from terminated steps but nothing happens.

Also, in my application.properties file I added a following property:

JavaScript

because I don’t want to allow Spring Batch automatically start new(not terminated) job. I need to start all new jobs manually(on user request) and restart all completed jobs after next application run.

How to configure Spring Batch in this case ?

UPDATED

Right now I’m trying to restart jobs with a following method:

JavaScript

but failing with a following exception:

JavaScript

Advertisement

Answer

I got it working by adding following line

JavaScript

into the restartUncompletedJobs method

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement