spring-boot

Minimum things required to develop Spring Boot APP

Raja shekhar
4 min readMar 23, 2021

--

As of now, we all know about spring boot applications and it’s development. As part of this article, we are going to look what are the minimum things required to develop a spring boot, and what is the purpose of each and every component in a detailed way. Let’s start …

To work with a spring boot application, add spring boot starter parent dependency, plugin spring-boot-maven-plugin, and one annotation @springBootApplication required. The above things are mandatory to work with spring boot applications whether it is a standalone or web application. If it is a web application then on top of this, spring-boot-starter-web dependency should be added in the application pom.xml

Adding spring boot starter parent, maven-plugin in application pom.xml

and the main class look like,

What is the purpose of each component mentioned above? will go through it one by one.

Spring Boot Starter Parent:

When we add this to application pom.xml then will get all the spring dependency from parent pom XML. No need to maintain any spring dependencies manually, everything will be taken care of spring boot starter parent. It will take care of the dependency version and third-party liberties(transitive dependencies). (like commons,CGLIB libraries adding while working with spring application). It will avoid incompatible version-type errors.

Spring boot maven plugin:

Java does support 3 types of archive types such as jar, war, and ear.Java supports adding a jar into a war, war into an Ear archive but it does not support the jar within the jar. To support this uber or fat jar came into the picture. we need to manually extract the jar and add those extracted classes to another jar and again have to build the jar that is called Ubar/flat jar. It has drawbacks like version, ambiguity on class identification, and difficulty to upgrade one of the dependency. But in spring boot we are adding all the spring dependencies into a single jar and we are directly running the executable jar. How does it support? Is there any kind of mechanism there?. Yes, spring boot people come up with one new archive type mechanism where they maintain both spring dependencies and other third-party dependencies as well. The executable jar packaging will take care by the maven plugin. When we ran the maven package goal, it will be created a new executable jar on top of the original jar. The following pictures will represent the same.

The maven created executable jar structure is,

@SpringBootApplication:

The executable jar which is created by the maven plugin will take the main class as the class which is annotated with @SpringBootApplication.If we have multiple main class in our application then we will get errors. To resolve those errors, we need to mention mainClass class tag in the maven plugin.

When we ran the main class, the spring boot will be creating an IOC container and instantiating the Environment object, and create bean definitions under classpath by scanning all the child packages by using @ComponentScan annotation(scans stereotype annotations and create bean definitions for those classes). By using @EnableAutoConfiguration , the spring boot will load all the configurations based on conditions.

--

--