Skip to content

Spring Boot application demonstrating core Spring Batch concepts, from basic Tasklets to advanced Chunk-oriented processing with error handling and scheduling.

Notifications You must be signed in to change notification settings

devraselmahmud/Spring-Batch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Batch Demo Project

A comprehensive Spring Boot application demonstrating core Spring Batch concepts, from basic Tasklets to advanced Chunk-oriented processing with error handling and scheduling.

🚀 Features

  • Chunk-oriented Processing: Efficiently handles data in chunks (Reader -> Processor -> Writer).
  • CSV to Database: Reads data from CSV files and persists them into an H2 database.
  • Fault Tolerance:
    • Skip Logic: Automatically skips malformed data.
    • Retry Logic: Retries failed operations (e.g., network issues).
    • SkipListener: Custom logging for skipped items.
  • Scheduling: Automated job execution using Cron expressions (configured for 2 AM daily).
  • H2 Console: Built-in web interface to inspect the database.
  • Dockerized: Ready to run in any containerized environment.

🛠️ Tech Stack

  • Java 17
  • Spring Boot 3.x
  • Spring Batch
  • H2 Database (In-memory)
  • Lombok
  • Docker

📋 Prerequisites

  • Docker (for containerized execution)
  • Maven (for local execution)

🏃 Getting Started

Local Execution

  1. Build the project:
    ./mvnw clean package -DskipTests
  2. Run the application:
    ./mvnw spring-boot:run

Docker Execution

  1. Build the Docker image:
    docker build -t spring-batch-demo .
  2. Run the container:
    docker run -p 8080:8080 spring-batch-demo

🔍 Verifying Data

Once the application is running, you can access the H2 console to verify the processed data:

  • URL: http://localhost:8080/h2-console
  • JDBC URL: jdbc:h2:mem:testdb
  • User: sa
  • Password: (empty)

Query the data:

SELECT * FROM USERS;

⚙️ Configuration

The job is currently configured to run every 10 seconds for testing purposes (via fixedRate in BatchScheduler.java). To switch to 2 AM daily, use the provided Cron expression:

@Scheduled(cron = "0 0 2 * * *")

About

Spring Boot application demonstrating core Spring Batch concepts, from basic Tasklets to advanced Chunk-oriented processing with error handling and scheduling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published