Review
In the previous section, we have laid down the functional specs of the application and examined the raw files that are to be imported. In this section, we will discuss the project's structure and write the Java classes.Table of Contents
Part 1: Introduction and Functional SpecsPart 2: Java classes
Part 3: XML configuration
Part 4: Running the Application
Project Structure
Our application is a Maven project and therefore follows Maven structure. As we create the classes, we've organized them in logical layers: domain, repository, service, and controller.Here's a preview of our project's structure:
The Layers
Disclaimer
I will only discuss the Spring Batch-related classes here. And I've purposely left out the unrelated classes because I have described them in detail already from my previous tutorials. See the following guides:- Spring MVC 3.1 - Implement CRUD with Spring Data Redis (Part 3)
- Spring MVC 3.1 - Implement CRUD with Spring Data MongoDB (Part 3)
- Spring MVC 3.1, jqGrid, and Spring Data JPA Integration Guide (Part 2)
Controller Layer
The BatchJobController handles batch requests. There are three job mappings:- /job1
- /job2
- /job3
What is a JobParameter?
"how is one JobInstance distinguished from another?" The answer is: JobParameters. JobParameters is a set of parameters used to start a batch job. They can be used for identification or even as reference data during the run:
Source: Spring Batch - Chapter 3. The Domain Language of Batch
Notice we have injected a JobLauncher. It's primary job is to start our jobs. Each job will run asynchronously (this is declared in the XML configuration).
What is a JobLauncher?
JobLauncher represents a simple interface for launching a Job with a given set of JobParameters:
Source: Spring Batch - Chapter 3. The Domain Language of Batch
Batch Layer
This layer contains various helper classes to aid us in processing batch files.- UserFieldSetMapper - maps FieldSet result to a User object
- RoleFieldSetMapper - maps FieldSet result to a Role object. To assign the user, an extra JDBC query is performed
- MultiUserFieldSetMapper - maps FieldSet result to a User object; it removes semi-colon from the first token.
- UserItemWriter - writes a User object to the database
- RoleItemWriter - writes a Role object to the database. To assign the user, an extra JDBC query is performed
Next
In the next section, we will focus on the configuration files. Click here to proceed.
Share the joy:
|
Subscribe by reader Subscribe by email Share
Thanks for the tutorial, It's just what I was looking for. Keep up the good work!!
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletecore java training in Electronic City
Hibernate Training in electronic city
spring training in electronic city
java j2ee training in electronic city
jordan 11
ReplyDeletegoyard
supreme new york
hermes birkin bag
supreme
jordan shoes
off white shoes outlet
off white nike
yeezy 500
yeezy