JobBuilderFactory was a helper bean in Spring Batch 4 that created JobBuilder instances already wired to the shared JobRepository, so you could write jobBuilderFactory.get("name") and chain steps. It is deprecated in Spring Batch 5 (Spring Boot 3) and removed in Spring Batch 6, and the replacement is to create new JobBuilder("name", jobRepository) directly. If you are upgrading, this is one of the first breaking changes you will hit.
This article explains what the factory did, why it was removed, and how to write the same job configuration in current Spring Batch.
In Spring Batch 4 the @EnableBatchProcessing annotation registered two helper beans, JobBuilderFactory and StepBuilderFactory. Each held the JobRepository (and, for steps, the transaction manager) and passed it to every builder it created. That removed repeated constructor arguments:
The get(name) call returned a JobBuilder. From there you configured the job incrementer, listeners, validator and the flow of steps, and build() returned the Job bean.
The factories hid two things that Spring Batch 5 wants to be explicit: which JobRepository a job uses and which PlatformTransactionManager a step uses. They also depended on @EnableBatchProcessing to create them. In Spring Batch 5, Spring Boot auto-configures the infrastructure itself, and the annotation is only needed when you want to customise it. Passing the repository directly is clearer, easier to test and works with several job repositories or data sources.
| Spring Batch 4 | Spring Batch 5 and later |
|---|---|
jobBuilderFactory.get("job") | new JobBuilder("job", jobRepository) |
stepBuilderFactory.get("step") | new StepBuilder("step", jobRepository) |
.chunk(100) | .chunk(100, transactionManager) |
@EnableBatchProcessing required | Not needed with Spring Boot 3 auto-configuration |
Inject the JobRepository and create the builder yourself:
The job name is the first constructor argument and, together with the identifying job parameters, forms a unique JobInstance in the metadata tables. The RunIdIncrementer adds a run.id parameter so you can launch the same job repeatedly.
Spring Boot 3 runs all Job beans at startup by default. Set spring.batch.job.enabled=false to stop that, or spring.batch.job.name=importJob to run one.
A job usually has several steps, so define each step with StepBuilder and chain them:
start and next run steps in sequence. For conditional flow, use .on("FAILED").to(otherStep) followed by .from(...) and .end(). Add listeners with .listener(...) and a parameters validator with .validator(...).
JobBuilderFactory with a JobRepository parameter.jobBuilderFactory.get("x") with new JobBuilder("x", jobRepository).StepBuilderFactory, and pass the transaction manager to chunk(size, tx) and tasklet(tasklet, tx).@EnableBatchProcessing if you use Boot's auto-configuration and have no customisation.BATCH_JOB_INSTANCE table for the expected rows.It was deprecated in Spring Batch 5 and removed in version 6. Use new JobBuilder(name, jobRepository) in all new code.
Usually not. Boot auto-configures the JobRepository, JobLauncher and related beans, and using the annotation switches that auto-configuration off.
Spring Boot creates it as a bean from your DataSource and the batch metadata schema. Inject it as a method parameter into your @Bean method.
Yes within a job repository. The name plus identifying parameters identify a JobInstance, so reusing a name for a different job mixes their history.
JobBuilderFactory used to supply pre-wired job builders in Spring Batch 4, but it is deprecated in Spring Batch 5 and gone in Spring Batch 6. Create jobs with new JobBuilder(name, jobRepository) and steps with new StepBuilder(name, jobRepository), pass the transaction manager explicitly, and rely on Spring Boot's auto-configuration instead of @EnableBatchProcessing.