Spring Batch is a lightweight framework for development of batch applications.
A batch job consists of multiple Steps. Each Step has ItemReader, ItemProcessor, and ItemWriter.
By default, Spring Batch executes all configured jobs at startup. We can disable job execution at startup by adding the following property to application.properties:
spring.batch.job.enabled=false
Project Structure

pom.xml

Student – The Entity class

StudentRepository – Spring Data JPA Repository

StudentItemReader – ItemReader provides the data

StudentItemProcessor – ItemProcessor transforms input items

StudentItemWriter – ItemWriter

database.properties

application.properties
![]()
AppConfig
The @EnableBatchProcessing annotation enables Spring Batch features and provides a base configuration for setting up batch jobs.
@StepScope – Spring container instantiates a new instance for each step execution.


Application

Console Output
Reading Students from DB:[Student [id=1, name=gyan, age=18, weight=70], Student [id=2, name=rochit, age=16, weight=55], Student [id=8, name=ravi, age=17, weight=65], Student [id=9, name=TEJA, age=14, weight=58], Student [id=11, name=VIKU, age=16, weight=44], Student [id=12, name=Ajay, age=16, weight=44], Student [id=15, name=Ramu, age=18, weight=47], Student [id=20, name=Sachin, age=14, weight=50], Student [id=21, name=Ramesh, age=14, weight=50], Student [id=23, name=Prabhakar, age=14, weight=50], Student [id=30, name=Mantu, age=15, weight=50]]
Processing Student:Student [id=1, name=gyan, age=18, weight=70]
Processing Student:Student [id=2, name=rochit, age=16, weight=55]
Processing Student:Student [id=8, name=ravi, age=17, weight=65]
Writing students to console.
GYAN:1:18:70
ROCHIT:2:16:55
RAVI:8:17:65
Processing Student:Student [id=9, name=TEJA, age=14, weight=58]
Processing Student:Student [id=11, name=VIKU, age=16, weight=44]
Processing Student:Student [id=12, name=Ajay, age=16, weight=44]
Writing students to console.
TEJA:9:14:58
VIKU:11:16:44
AJAY:12:16:44
Processing Student:Student [id=15, name=Ramu, age=18, weight=47]
Processing Student:Student [id=20, name=Sachin, age=14, weight=50]
Processing Student:Student [id=21, name=Ramesh, age=14, weight=50]
Writing students to console.
RAMU:15:18:47
SACHIN:20:14:50
RAMESH:21:14:50
Processing Student:Student [id=23, name=Prabhakar, age=14, weight=50]
Processing Student:Student [id=30, name=Mantu, age=15, weight=50]
Writing students to console.
PRABHAKAR:23:14:50
MANTU:30:15:50