How Spring Boot run batch jobs
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Spring Boot runs batch jobs through Spring Batch infrastructure that it auto-configures when the right dependencies are present. In the common startup flow, Boot detects Job beans, creates the supporting batch components, and launches eligible jobs automatically unless you tell it not to.
The Main Pieces Spring Batch Uses
A Spring Batch application usually revolves around a few core concepts:
- '
Job: the full batch workflow' - '
Step: one stage of that workflow' - '
JobRepository: metadata about job executions' - '
JobLauncher: the component that starts jobs'
Spring Boot helps by auto-configuring much of this plumbing so you can focus on defining the job itself.
A Minimal Batch Job in Spring Boot
Here is a small example with one tasklet-based step:
If this application starts with batch auto-run enabled, Spring Boot can launch exampleJob automatically at startup.
Why the Job Runs on Startup
When Spring Boot sees Spring Batch on the classpath and finds batch job beans, it can use a job-launching runner during application startup. That is why developers are often surprised to see their batch job execute immediately after the application context finishes loading.
In other words, the job is not running by magic. It is being launched by startup infrastructure that Boot wires in for you.
How to Control Which Jobs Run
If you want only a specific job to run, configure it explicitly in application properties:
If you do not want jobs to auto-run at startup at all:
Then you can launch jobs yourself through JobLauncher, a scheduler, an API endpoint, or some other trigger.
Manual Job Launching
Here is a simple manual launch example:
Using a timestamp parameter avoids accidental job-instance collisions when the same job is launched repeatedly.
Chunk Steps Versus Tasklets
The example above uses a tasklet because it is compact. Real batch systems often use chunk-oriented processing for reading, transforming, and writing many records. Spring Boot does not change that model. It simply makes it easier to wire the infrastructure and external configuration around it.
So when people ask how Spring Boot runs batch jobs, the practical answer is:
- Spring Batch defines the execution model.
- Spring Boot auto-configures the infrastructure.
- A launcher or runner starts the job.
Common Pitfalls
The most common mistake is forgetting that jobs may auto-run on startup. That can surprise developers during local testing.
Another issue is running the same job with the same parameters and then wondering why nothing new happens. Spring Batch tracks job instances by parameters.
Teams also disable auto-run and then forget to add another trigger path, which makes it look as though the job definition is broken when it simply is not being launched.
Summary
- Spring Boot runs batch jobs by auto-configuring Spring Batch infrastructure and launching detected jobs.
- '
Job,Step,JobRepository, andJobLauncherare the main moving parts.' - Jobs can auto-run at startup unless you disable that behavior.
- Use properties such as
spring.batch.job.nameandspring.batch.job.enabledto control startup execution. - For repeated launches, vary job parameters so Spring Batch treats each run as a new job instance.
Related reading
- How Spring Kafka Consumer skips from Avro Deserializer exception
- How to access a Spring Boot Application's name programmatically?
- How to access a value defined in the application.properties file in Spring Boot
- How to access a value defined in the application.properties file in Spring Boot
- How to access entity manager with spring boot and spring data
- How to access outer class from an inner class?
- How to access Spring-boot JMX remotely
- How to acknowledge current offset in spring kafka for manual commit

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.