Created by Rod Johnson in 2003, released under Apache 2.0 license, the most popular application development framework for enterprise Java, an Open source Java platform, provides to create high performing, easily testable and reusable code, organized in a modular fashion, simplifies java development
Spring Framework
Enables Plain Old Java Object (POJO) based programming model
With POJO you don't need EJB container product
Utilizes existing technologies like ORM frameworks, logging frameworks, JFS, Struts
Spring Framework
Is a well-designed web model-view-controller (MVC) framework (a great alternative to Struts)
Provides a coherent transaction management interface (JTA)
Provides a suitable API for translating technology-specific exceptions (for instance, thrown by JDBC, Hibernate, or JDO,) into consistent, unchecked exceptions
The Inversion of Control (IoC) containers are lightweight, especially when compared to EJB containers. Being lightweight is beneficial for developing and deploying applications on computers with limited resources (RAM&CPU)
Testing is simple because environment-dependent code is moved into this framework
The Spring IoC container makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application
Batch processing
A processing mode which involves execution of series of automated complex jobs without user interaction, handles bulk data and runs for a long time
Several Enterprise applications require to process huge data to perform operations involving time-based events such as periodic calculations, periodic applications that are processed repetitively over large datasets, and applications that deals with processing and validation of the data available in a transactional manner
Spring Batch
A lightweight framework which is used to develop Batch Applications that are used in Enterprise Applications, in addition to bulk processing, this framework provides functions for including logging and tracing, transaction management, job processing statistics, job restart, and resource management
Spring Batch Architecture
A job can consist of 'n' number of steps, each step contains Read-Process-Write task or it can have single operation, which is called tasklet, Read-Process-Write is basically read from a source like Database, CSV etc. then process the data and write it to a source like Database, CSV, XML etc., Tasklet means doing a single task or operation like cleaning of connections, freeing up resources after processing is done, Read-Process-Write and tasklets can be chained together to run a job
A basic Batch Application will simply execute a tasklet to display a message
A Spring Batch application contains the following files: Configuration file, Context.xml, Tasklet class, Launcher class
Tasklet class
Implements the Tasklet interface and contains the processing code for the job (in this case, it displays a simple message)
Launcher class
Launches the Batch Application by running the Job launcher
Spring Batch Processing Operations include Read-Process-Write and Tasklets
Spring Batch API provides functionality for Batch Application development
Steps to Develop Batch Application
1. Create the product entity
2. Create the Processor Class for the task
3. Create Job Execution Listener (optional)
4. Step Creation
5. Job Creation
6. Job Launcher Creation
7. Run the application
The sample-data.csv file contains data in the format: Jill,Doe, Joe,Doe, Jake,Doe, Jane,Doe, John,Doe
FlatFileItemReader
Reads data from the sample-data.csv file, delimited by commas, and maps the data to the Person class
PersonItemProcessor
Processes the Person data by converting the first and last names to uppercase
JdbcBatchItemWriter
Writes the processed Person data to a MySQL database table named 'people'