This project showcases the capabilities of Spring Batch to efficiently handle bulk data operations, specifically the import of contacts from a CSV file to a database.
This project is the accompanying source code to a full tutorial on https://tucanoo.com/spring-batch-example-building-a-bulk-contact-importer/
Spring Batch provides powerful functionalities for processing large volumes of records, including transaction management, chunk processing, and handling of errors. This demonstration imports a sample CSV file containing 100,000 contact records into a database, allowing users to experience and understand the efficiency and flexibility of Spring Batch.
- Java 17
Clone and run the app either via your IDE or command line.
After the application starts:
-
Trigger the batch job by navigating to the following endpoint in your browser or using an API client (e.g., Postman):
http://localhost:8080/importExample/start
This initiates the import process using the sample CSV file
100k_sample_contacts.csv
which can be found under src/main/resources -
To monitor the progress and status of the import job, visit:
http://localhost:8080/importExample/status
This endpoint provides details about the current status of the batch job, including the number of records read/written, progress percentage, and more. You can repeatedly refresh this page to monitor progress until completion.
-
The batch configuration is located in
BatchImportConfigForContacts
. This class defines the reader, writer, and the step to execute the batch job. -
ContactImportController
offers endpoints to start the batch job and monitor its status. -
The project leverages Spring Batch's
JobLauncher
,Job
, andJobExplorer
to control and inspect the batch operation.
Spring Batch offers a powerful solution for efficiently and reliably processing large datasets. This project provides a tangible example of its capabilities and serves as a reference for developers aiming to integrate similar features into their solutions.
For further reference, please consider the following sections:
For further assistance with this or Spring Boot development contact: