Spring Batch Example
Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems.
Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job restart, skip, job processing statistics and resource management. It also provides more advanced technical services and features that will enable extremely high-volume and high performance batch jobs through optimization and partitioning techniques. It is simple as well as complex, high-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.
- Chunk based processing
- Declarative I/O
- Transaction management
- Web based administration interface
Spring Boot Config
Spring Boot provides a spring-boot-starter-batch dependency.
By default, batch applications require a DataSource to store job details. If you want to deviate from that, you need to implement BatchConfigurer
Executing Spring Batch Jobs on Startup
Spring Batch auto-configuration is enabled by adding @EnableBatchProcessing (from Spring Batch) in your context.
By default, it executes all Jobs in the application context on startup. You can narrow down to a specific job or jobs by specifying spring.batch.job.names (it takes a comma-separated list of job name patterns).
Note: Unlike command line option arguments that set properties in the Environment (i.e. by starting with –, such as –my-property=value), job parameters have to be specified on the command line without dashes (e.g. jobParam=value).
If the application context includes a JobRegistry, the jobs in spring.batch.job.names are looked up in the registry instead of being autowired from the context. This is a common pattern with more complex systems, where multiple jobs are defined in child contexts and registered centrally.
How to create a spring Batch project
If you want to create your own Spring Boot-based and spring security project, visit Spring Initializr, fill in your project details, pick your options, and you can download either a Maven build file, or a bundled up project as a zip file.