RoadToWebDev Day#6-Spring Boot

This is a part of my ongoing series about exploring the Road To Web Development, you can find rest of the blogs here

What is Spring Boot?

Spring Boot is an open-source Java-based framework that is built on the top of the Spring Framework. The conventional definition of the Spring Boot is “it provides a good platform for Java developers to develop a stand-alone and production-grade spring application that you can just run.” But it is quite important to know why should anyone use Spring Boot!

But, before we start discussing on Spring Boot, there are some concepts on Maven and POM.xml that you need to know.

Maven is powerful project management built tool that helps to build, documenting, and managing a project. The built tool takes care of everything in building a project. Maven is chiefly used for Java-based projects. It helps in downloading dependencies(external Java libraries required for Project) and repositories(directories of packaged JAR files).

Maven is based on POM(Project Object Model). POM is a building block in Maven. It is an XML file that contains all the information about the project and configuration details used by Maven to build a project. That we call as POM.xml file.

Maven looks for the POM in the current directory in order to perform a certain task or a goal. Maven reads the pom.xml file, gets the required configuration details or information, and then runs the required task. And that’s how it works!

So far, we know that Maven is a Build automation/Project management tool while Spring boot provides RAD (Rapid Application Development) feature for applications using the spring framework. Let us go in a bit detail about Spring Boot and why to use it.

The Spring Boot helps the developers to contribute more time in writing code, rather than setting up the configurations for the required environment. So here are some salient features of the Spring Boot to make you understand why to use it.

  • AutoConfiguration :

Spring Boot helps setting up the application according to the surrounding environment. It makes certain assumptions on the basis of dependencies added by the user in pom.xml file. For example, if the user has added dependency of a specific database say MySQL then the Spring Boot will configure that specific database access as the user needs. We can say that Spring Boot saves time and unnecessary effort of the user.

Only a single step is needed to add the AutoConfiguration feature to your Spring Boot application. That is to add @EnableAutoConfiguration annotation to your project. I have discussed some of the important Spring Boot annotations in the next article.

  • Being Standalone:

Spring Boot reduces the number of steps to be performed for the process of starting your Java-based application. Let’s see how it differs…

While executing the java project without spring framework we need to perform:

  1. Package the Application
  2. User needs to choose the type of web server and download it.
  3. Configure the specific web server.
  4. Organize the deployment process and to start the webserver.

Deploying means getting the software or hardware up and running properly in its environment, including installation, configuration, running, testing, and making necessary changes.

Whereas with Spring Boot you need to only perform:

  1. Package the Application
  2. Run it with some simple command like java -jar my-application.jar

Spring Boot takes care of the rest by starting and configuring an embedded web server and deploys your application there.

  • Opinionated:

We already discussed this point that Spring Boot follows opinionated default configuration so it reduces the developer efforts. Spring boot always uses sensible opinions, mostly based on the classpath contents. So it overrides the default configuration.

Important modules of the Spring Framework:

  • Dependency Injection:

The simplest definition of Dependency Injection would be “an ability of an object/framework to inject/append dependencies of another object/framework.”

Dependency injection is the art of creating service/client relationships that work well together by injecting services that are easily swapped with minimal time and effort.

In other words, the process of creating an object for some other class and let the class directly using the dependency is called Dependency Injection.

Its goal is to improve the reusability of the code and aim to reduce the frequency with which you need to change a class. It enables you to replace dependencies without changing the class that uses them.

Dependency injection also makes testing easier.

  • Inversion Of Control(IOC):

As the name suggests, IOC is about inverting the control flow of the program as compared to traditional control flow. It enhances the modularity of the program and it makes the program extensible.

Inversion of Control is a key part of what makes a framework different from a library.

A library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client whereas a framework does some work for you, you just need to plug your behavior into some places by either by subclassing or by plugging into your own classes. Then framework will call your code when it is required.

Inversion of Control can be achieved through various mechanisms such as Strategy design pattern, Service Locator pattern, Factory pattern, and Dependency Injection (DI).

  • Aspect Oriented Programming(AOP):

AOP provides modularity to the program. Hence this way, it complements OOP. We know that the key unit for OOP is class, but here it is considered as aspect. AOP breaks the program logic into distinct parts called concerns.

The concern is the behavior we want to have in a particular module of the program. It can be defined as the functionality we want to implement.

The cross-cutting concern is a concern that is applicable throughout the program. This affects the entire application. For example, logging, security, and data transfer are the concerns needed in almost every module of an application, thus they are the cross-cutting concerns.

AOP enhances the modularity of the program by adding additional behavior to existing code without modifying the code itself, instead separately specifying which code is modified via a “pointcut” specification, such as “log all function calls when the function’s name begins with ‘set’”.

  • Model View Controller(MVC):

The Spring Web MVC framework provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications.

It implements all the basic features of a core spring framework like Inversion of Control, Dependency Injection.

Models are responsible for encapsulating the application data. The Views render a response to the user with the help of the model object. Controllers are responsible for receiving the request from the user and calling the back-end services.

The Model-view-controller design pattern helps in separating the business logic, presentation logic, and navigation logic.

  • Transaction Management:

The sequence of actions that will be performed to complete database operation and its management is known as Transaction Management.

Transaction management is an important part of an RDBMS-oriented enterprise application to ensure data integrity and consistency.

Spring transaction management tries to resolve the problem of both transactions i.e Global Transaction and Local Transaction(Local transactions are specific to a single transactional resource like a JDBC connection, whereas global transactions can span multiple transactional resources like transaction in a distributed system). A consistent programming model approach can be used in any environment. The same code will work for different transaction management in different environments.

In a nutshell, the main goal of the Spring Boot framework is to reduce overall development time and increase efficiency by having a default setup for common development use cases.

Hope you understood the article!!!


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store