Spring Boot
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.
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.
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