Driver Program and Job Implementation: Part I
Let’s go through the driver's code and highlight the code flow by describing and running the skeleton of the application.
Working with the batch project
Let’s dive straight into describing the code and start by analyzing the first feature branch we are going to be working on, which contains the skeleton of the SparkBatchApp
application.
The widget below contains the codebase, but if we follow the versioning strategy described in the previous lesson, we branch off the Main or Development branch by executing a git command with the following structure:
git clone --branch feature/app_skeleton [REPOSITORY_URL]
Note: The
clone
git command is used here because we are checking the code out for the first time. After this, if we worked in different branches, we simply need to use thecheckout
git command, provided the branches are created in the repository. Examples of this are shown in other lessons of this chapter.
mvn install -DskipTests java -jar /usercode/target/batch-app-0.0.1-SNAPSHOT.jar jobName=sparkJob
Note: It’s always a better choice to autowire Spring beans through a constructor method. It provides many benefits, such as having beans initialized with all their dependent beans, easier testing of classes and use of mocked beans, and so on. In the
SparkBatchApp
main class, we are not following this practice because it’s a particular type of Spring bean (it implements a Spring Interface, which makes it the main entry point of the Spring boot application), and we aren’t testing it.
Code walkthrough
As mentioned in the previous lesson, this is a Spring-backed application. Specifically, it uses Spring Boot and some of its modules for different application layers, such as persistence (Spring JPA), and so on.
Let’s describe what this framework brings to this project.
Spring auto-configuration in the batch application
The first upside of using Spring Boot, albeit at the cost of the application’s jar size, is taking advantage of the framework’s opinionated nature.
The word “opinionated” translates here to following Spring conventions for auto-configuration around certain aspects of an application. In plain English, this can be read as: “Let Spring configure and manage some parts of the application’s initialization and set up for us.”
In our application, we take ...