Code Structure Overview

We can create Spring boot project with the help of STS tool or Spring boot initializr.

Spring boot application code base mainly have four major modules:

  1. Java Packages
  2. application.properties file
  3. pom.xml file
  4. Spring Boot main Java application File

Java Packages

It is used organize all the classes and interfaces related to application. Packages can have any custom name with all lower case to avoid conflicts.

All Java packages gets created inside src/main/java folder.

Below are the main packages required for any of the Spring boot application:

com.example.demo.controller
This package will contain all the controller classes.

com.example.demo.bean
This package will contain all the beans class with private variable and setter getter method.

com.example.demo.dao
This package will contain all the database persistence logic classes and interfaces.

com.example.demo.service
The package will contain classes and interfaces having business logic related to project.

application.properties File

This file is to declare project level properties or configurations. It can be for both built-in and custom classes. application.properties file located inside src/main/resources folder.

Creating project using STS tool or Spring initializr by default will create application.properties file.

Below is the example to declare configurations related to Spring database inside application.properties.

pom.xml File Dependencies

pom.xml file is to declare required Spring boot dependencies. This file by default gets created at the time of project creation using STS tool or Spring initializr.

The main advantage of Spring boot pom.xml file as it is not require to declare version for any of the pom dependency under <dependencies> tag. It will automatically include depending on Spring Boot Starter Parent version dependency.

Below pom dependency as Spring Boot Starter Parent helps us to manage all other Spring Boot Starters dependencies included as part of <dependencies> tag as shown below.

Spring Boot main Java application File

Below is the main Java application file which helps us to start Spring Boot Application having @SpringBootApplication as an annotation on top of the class with main methods defined.

Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.

0