0% found this document useful (0 votes)
93 views

Spring Boot

Spring Boot is a Java-based framework for creating microservices. It allows developers to build standalone and production-ready Spring applications that can be deployed independently. The project directory structure separates code into layers like controllers, services, repositories etc. Services define CRUD methods without directly accessing models, while repositories provide data access. Controllers call services and return DTOs instead of full models to the UI layer.

Uploaded by

Sarowar sojol
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Spring Boot

Spring Boot is a Java-based framework for creating microservices. It allows developers to build standalone and production-ready Spring applications that can be deployed independently. The project directory structure separates code into layers like controllers, services, repositories etc. Services define CRUD methods without directly accessing models, while repositories provide data access. Controllers call services and return DTOs instead of full models to the UI layer.

Uploaded by

Sarowar sojol
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. What is spring boot?

Spring Boot is an open source Java-based framework used to create a micro Service. It
is developed by Pivotal Team and is used to build stand-alone and production ready
spring applications. Micro Service is an architecture that allows the developers to
develop and deploy services independently. Each service running has its own process
and this achieves the lightweight model to support business applications.

2. Why to use spring boot application?


Spring’s dependency injection approach encourages writing testable code Easy to use
but powerful database transaction management capabilities Spring simplifies integration
with other Java frameworks like JPA/Hibernate ORM, Struts/JSF/etc. web frameworks
State of the art Web MVC framework for building web applications Spring framework
provides flexibility to configure beans in multiple ways such
as XML, Annotations, and JavaConfig. Spring Batch: Provides powerful batch
processing framework. Spring Security: Robust security framework to secure
applications. Spring Social: Supports integration with social networking sites like
Facebook, Twitter, LinkedIn, GitHub, etc.

3. Project Directory Structure


This is the overall project directory structure of event api system. All the necessary
coding for developing back-end system of an application are placed inside this
src/main/java and they are divided into different layers according to their functionality.
For example, all types of exceptions that may occur are managed in the
exceptionHandler layer. Then those classes which serve security purpose for example
authentication, authorization are stored within security layer. We have in details
demonstration of these layers in the later part of this presentation. The file named
application.properties placed in src/main/resources is used to configure database,
application port, database source, data storage mechanism etc. moreover, all the
UserInterface or front end classes can be placed within this src/main/resources folder.
All the claases related to testing are placed within src/test/java. Finally, all kinds of
dependencies to run spring boot application are included in pom.xml. For example, web
dependency, database dependency, JPA dependency those are included in the pom.xml
file.

4. Models and Dtos


An entity(Model) represents a table stored in a database. Every instance of an entity represents
a row in the table. DTOs let us transfer only the data that we need to share with the user
interface and not the entire model object that we may have aggregated using several sub-
objects and persisted in the database. The mapping of models to the DTOs can be handled using
ModelMapper utility, however its only useful when your DTO is almost similar (literally) to the
concerned models which is not always the case and hence I prefer using custom mapper classes.
DTOs are not meant to be the mirror image of their model counterparts, rather they should be a
reflection of what the user interface or the api response demands.

5. Exhibitor Model
Exhibitor entity represents exhibitors table in the database. Since its an entity so we have to
mark this with @Entity annotation and also we can specify the table name. @getter and
@Setter help us to shorten our code and it automatically defines getter and setter method for
all the properties defined in an Entity model. Also the relationships of other classes with this
class are mentioned. For example, one eventmasterEntity can have many exhibitorEntity and so
we have specified their relationship using @ManyToOne annocation. So we will have an
exhibitors table with eventType, onlineType ……………. Columns in the database.

6. ExhibitorDto Model
DTOs let us transfer only the data that we need to share with the user interface and not the
entire model or entity object that we may have aggregated using several sub-objects and
persisted in the database. There are different opinions about whether we should use DTOs or
not but not using DTOs makes our model layer very tightly coupled with the UI layer and that is
something that no enterprise project should ever get into. DTOs are not meant to be the mirror
image of their model counterparts, rather they should be a reflection of what the user interface
or the api response demands.

7. Service layer and ServiceImpl layer


All the interfaces which are implemented in serviceImpl Layer are stored in service layer. Mainly
controller layer interacts with service layer for any kind of data manipulation and logical
operation. All types of business logics are implemented within this serviceImpl layer to make the
controller as simple as possible.

8. So here an EventMasterService class is mentioned where all the CRUD operation’s methods are
declared. Controller layer basically call these methods from controller layer. And these services
are implemented in EventMastereServiceImpl layer. All the business logics are implemented
there. This is beacause we can anytime extend this class and implemenet different types of
logics from the serviceimpl layer. The main thing is, the service layer never accepts a model as
input and never ever returns one either. This is another best practice that Spring developers
should follow in a layered architecture. The controller layer interacts with the service layer to
get a job done whenever it receives a request from the view or api layer, when it does it should
not have access to the model objects and should always converse in terms of neutral DTOs.
9. This is the eventMastrrerServiceImpl layer where all those 6 methods mentioned in service layer
been implemented. Since this class is providing services which are needed by the user through
controller layer, therefore this class is annotated with @Service annotation. Moreover, all the
dependencies which are needed to perform the functionality of this class are injected using
@Autowired annotation. Then, methods have been overridden and implemented.
10. This layer is called data Access layer or DAO. This layer is mainly responsible for accessing data
from the database. They are all extensions of the databaseRepository interface helping the
service layer to persist and retrieve the data from database.
11. We can see, in EventMasterRepository class we have declared 2 methods. However, this
interface has lot more methods implemented for example getUserByUsername() method. but
for this application to work appropriately we need this two methods. This repository layer
mainly gets called from the service layer for accessing data from the database.
12. Request layers are used to send a post request or put request data to an Endpoint and response
layer is used to send response from an endpoint in an API.
13. For example here we can see ExhibitorRequestModel, instance of this class will be used to send
data while performing a create request to the createexhibitor endpoint to the
exhibitorcontroller. Since, this is the structure we used to send the data so validation logic are
included with this class.

14.

15. the most important part is the controller layer. It binds everything together right from the moment a
request is intercepted till the response is prepared and sent back. The controller layer is present in the
controller package, the best practices suggest that we keep this layer versioned to support multiple
versions of the application and the same practice is applied here.

16. since this is a restcontroller so we have defined it using @Restcontroller. We have mapped all those
6 operations we need to manipulate data. We have mapped those methods using getmapping,
postmapping. For update we have declared utmapping etc.

17. @EnableJPARepositoru
Annotation to enable JPA repositories. Will scan the package of the annotated configuration class for
Spring Data repositories by default.
@SpringApplication

Spring Boot @SpringBootApplication annotation is used to mark a configuration class that


declares one or more @Bean methods and also triggers auto-configuration and component
scanning. It's same as declaring a class with @Configuration, @EnableAutoConfiguration and
@ComponentScan annotations.

You might also like