JobLauncher is the Spring Batch interface that starts a Job with a given set of JobParameters and returns a JobExecution describing the run. It is the entry point you call from a scheduler, REST controller, command-line runner or message listener. It does not define the job itself: the job's steps, readers and writers live in the Job bean, and the JobRepository stores the metadata.
In Spring Batch 5 (Spring Boot 3) the default implementation is TaskExecutorJobLauncher, which replaced SimpleJobLauncher. Newer Spring Batch 6.x releases move launching toward JobOperator, so check the release notes of the version you use before building new code on JobLauncher.
The interface has one method:
Calling run() does four things:
JobRepository for the JobInstance identified by the job name and the identifying parameters.JobExecution with status STARTING.JobExecution (immediately or after completion, depending on the task executor).| Collaborator | Responsibility |
|---|---|
Job | The configured flow of steps |
JobParameters | Input values that identify and customise a run |
JobRepository | Persists JobInstance, JobExecution and StepExecution metadata |
JobLauncher | Validates the request and starts the execution |
The following Spring Boot 3 configuration defines a job and launches it from a service. Since Spring Batch 5, JobBuilder and StepBuilder take the JobRepository directly, and @EnableBatchProcessing is not needed with Boot auto-configuration (adding it switches the auto-configuration off).
The requestedAt parameter matters. Parameters are identifying by default, so launching the same job with the same parameters twice is treated as the same JobInstance. If the first run completed, the second call fails with JobInstanceAlreadyCompleteException. Add a unique parameter (a timestamp or a run id) when you want a fresh instance each time.
TaskExecutorJobLauncher uses a TaskExecutor to run the job. The default executor is synchronous, so run() blocks until the job ends. That is fine for a command-line job, but a web request would hang until the batch finishes.
To return immediately, give the launcher an asynchronous executor and poll the returned JobExecution (or look it up later by id):
With this launcher, run() returns a JobExecution whose status is still STARTING or STARTED. Check getStatus() and getExitStatus() later, or query JobExplorer. If you define your own launcher bean, remember that Boot's auto-configured one backs off, so inject the one you want by name or qualifier.
| Exception | When it is thrown |
|---|---|
JobExecutionAlreadyRunningException | An execution of the same instance is still running |
JobInstanceAlreadyCompleteException | The instance already finished successfully |
JobRestartException | The job is not restartable or the restart is invalid |
JobParametersInvalidException | A JobParametersValidator rejected the parameters |
A failed execution can be restarted by launching the same job with the same identifying parameters, which resumes from the failed step if the job is restartable. Use JobParametersBuilder.addString(name, value, false) for non-identifying parameters that should not create a new instance.
Spring Boot launches every Job bean at application start through JobLauncherApplicationRunner. To launch jobs yourself, disable that behaviour:
To run one named job at startup only, set spring.batch.job.name=reportJob. For recurring runs, call your service from a @Scheduled method, an external scheduler such as Kubernetes CronJob, or a REST endpoint, and always pass a changing parameter.
No. JobLauncher only starts jobs. JobOperator adds operations such as stop, restart and abandon by execution id, and in recent Spring Batch versions it takes over launching as well.
The parameters are identical to a completed run, so Spring Batch sees the same JobInstance as already complete. Add a unique identifying parameter.
Configure TaskExecutorJobLauncher with an asynchronous TaskExecutor and read the status from the returned JobExecution or from JobExplorer.
Boot runs all job beans at startup by default. Set spring.batch.job.enabled=false to stop it.
JobLauncher starts a Job with JobParameters and returns a JobExecution. It validates restart rules through the JobRepository, runs the job synchronously unless you provide an asynchronous TaskExecutor, and reports problems through specific exceptions. Use unique identifying parameters for each new run, disable startup execution when you launch jobs programmatically, and check the notes of your Spring Batch version about JobOperator.