Spring Batch XML Config by Spring Boot

How to start Spring Batch XML Config – use Spring Boot

Many business operations need to process with batch job for critical environment. Spring Batch is a lightweight framework to boot the batch application.

For starting, you can follow the How to start with Spring Batch using Spring Boot – Java Config. In the tutorial I will guide you how to start with XML config.

Related Articles:
How to start with Spring Batch using Spring Boot – Java Config
How to use Intercepting Job Execution in Spring Batch
How to use Spring Batch Restartable Function
Spring Batch – Programmatic Flow Decision
How to import CSV data to PostgreSQL Database using Spring Batch Job

I. Structure of project Spring Batch XML Config

spring batch xml config

II. Spring Batch XML Config

Follow How to start with Spring Batch using Spring Boot – Java Config, we have a BatchConfig class as below:

package com.javasampleapproach.springbatch.config;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.javasampleapproach.springbatch.step.Processor;
import com.javasampleapproach.springbatch.step.Reader;
import com.javasampleapproach.springbatch.step.Writer;
public class BatchConfig {
    public JobBuilderFactory jobBuilderFactory;
    public StepBuilderFactory stepBuilderFactory;
    public Job job() {
        return jobBuilderFactory.get("job")
                .incrementer(new RunIdIncrementer())
    public Step step1() {
        return stepBuilderFactory.get("step1")
                . chunk(1)
                .reader(new Reader())
                .processor(new Processor())
                .writer(new Writer())

Now we can change solution with XML config:

<beans:beans xmlns="http://www.springframework.org/schema/batch"
	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

	<job id="job">
		<step id="step1">
				<chunk reader="itemReader" processor="itemProcessor" writer="itemWriter" commit-interval="1" />
	<beans:bean id="itemReader" class="com.javasampleapproach.springbatch.step.Reader"/>
	<beans:bean id="itemProcessor" class="com.javasampleapproach.springbatch.step.Processor"/>
	<beans:bean id="itemWriter" class="com.javasampleapproach.springbatch.step.Writer"/>


III. Source code

Spring Batch – XML Config

By grokonez | October 10, 2016.

Last updated on April 26, 2021.

Related Posts

2 thoughts on “Spring Batch XML Config by Spring Boot”

  1. Why you did not configured the “JobRepository”, “JobLauncher” etc ? This may be very useful in some situations. Please reply.


Got Something To Say:

Your email address will not be published. Required fields are marked *