PFB the link reference for basic spring boot projects and concepts,
1)Spring Boot architecture has below listed 4 layers,
1.1)Presentation layer
This layer handles the HTTP requests, translates the JSON parameter to object, and authenticates the request and transfer it to the business layer. In short, it consists of views i.e., frontend part.
1.2)Business layer
This layer handles all the business logic. It consists of service classes and uses services provided by data access layers. It also performs authorization and validation.
1.3)Persistence layer
This layer contains all the storage logic and translates business objects from and to database rows.
1.4)Database layer
In the layer, CRUD (create, retrieve, update, delete) operations are performed.
2)Spring Boot flow architecture,
3.1)The below listed packages executed are executed as below mentioned order,
3.1.1)Master package(auto generated)
3.1.2)Controller
3.1.3)Request
3.1.4)Service
3.1.5)Repository
3.1.6)Model
3.1.7)Service
3.1.8)Abstracted response
3.1.9)Response
3.1.10)Service
3.1.11)Controller
3.2)The request and response flow will go through spring boot contains java classes like below explained,
3.2.1)Initially, master package(auto created) contains 'static run method' will execute and load the configurations and identifies the packages. This class has annotated as @SpringBootApplication and it used to enable the following annotations,
3.2.1.1)@EnableAutoConfiguration annotation enables the Spring Boot auto-configuration mechanism.
3.2.1.2)@ComponentScan annotation scans the package where the application is located.
3.2.1.3)@Configuration annotation allows us to register extra beans in the context or import additional configuration classes.
3.2.2)@SpringBootApplication annotation identifies the which class has declared by @Controller (or) @RestController annotation. In this controller class handling the requests and converts into java acceptable objects.
3.2.3)In this controller we are adding the request class which has created based on request contains parameters.
3.2.4)The @SpringBootApplication annotation will identifies the model class which has declared by @Entity and if that finds @Table, @Id and @Column annotations; it will creates table and columns by default.
3.2.8)We are getting the data from JSON request. We can't send those request data directly to database; because request contains data may irrelevant to our database contains columns.
Ex:
Database contains columns,
Emp_Roll_No
Emp_Name
Emp_Name
Model class contains parameter,
Emp_Roll_No
Emp_Name
Emp_Name
Request / Request class contains the data,
empRollNo
empName
empAddress - irrelevant request data
This 'empAddress' is not available in database columns list.
In this case we need build the request before sending it to the database.
3.2.9)Then flow comes into Model package again compare the model class contains variables with request class contains variables and assign the request variables data into model class variables.
3.2.11)Once database activities has completed; we need to send the response to client.
3.2.12)We can't directly send database response to client; because database contains many number of column which are like createdBy, createdDate ...,etc. so, those data are required to client.
Ex:
Client wants response like,
{
"empRollNo" : "100",
"empName" : "Somu"
}
Database response:
{
"empRollNo" : "100",
"empName" : "Somu",
"CreatedBy" : "Admin",
"CreatedDate" : "01-aug-2021"
}
In this case CreatedBy and CreatedDate are not required. So we need build the database response before sending it to client.
In this case CreatedBy and CreatedDate are not required. So we need build the database response before sending it to client.
3.2.13)Code flow will comes into response abstraction (abstracting the client need data from database response). The Dto package will execute and we will set the database responses into abstractDto class variables
3.2.14)Finally abstracted response will be returns to client through service >> controller
Previous session: Click to know - How to install Lombok in STS tool?
Context page: Click here
Home page: Click here
Thanks, I hope you enjoyed this session !!!.
-Somasundar Kanakaraj