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;
 
@Configuration
public class BatchConfig {
 
    @Autowired
    public JobBuilderFactory jobBuilderFactory;
 
    @Autowired
    public StepBuilderFactory stepBuilderFactory;
 
     
    @Bean
    public Job job() {
        return jobBuilderFactory.get("job")
                .incrementer(new RunIdIncrementer())
                .flow(step1())
                .end()
                .build();
    }
 
    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                . chunk(1)
                .reader(new Reader())
                .processor(new Processor())
                .writer(new Writer())
                .build();
    }
}

Now we can change solution with XML config:



	
		
			
				
			
		
	
	
	
	
	


III. Source code

Spring Batch – XML Config



By grokonez | October 10, 2016.

Last updated on June 4, 2017.



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.

    Thanks,
    Savani

Got Something To Say:

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

*