A comprehensive Spring Boot application demonstrating core Spring Batch concepts, from basic Tasklets to advanced Chunk-oriented processing with error handling and scheduling.
- 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.
- Java 17
- Spring Boot 3.x
- Spring Batch
- H2 Database (In-memory)
- Lombok
- Docker
- Docker (for containerized execution)
- Maven (for local execution)
- Build the project:
./mvnw clean package -DskipTests
- Run the application:
./mvnw spring-boot:run
- Build the Docker image:
docker build -t spring-batch-demo . - Run the container:
docker run -p 8080:8080 spring-batch-demo
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;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 * * *")