1- Fundamentals of Spring and Spring MVC
In order to have good understanding of Spring boot we need understanding of some of the concepts of Spring and Spring MVC framework
What is spring framework?
Spring framework is an open source Java platform.
Spring is a Dependency Injection framework to make java application loosely coupled.
Loosely coupled make things such a way that modules can be changed easily.
OR
The Spring Framework is an application framework and inversion of control container for the Java platform.
The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE (Enterprise Edition) platform.
What is REST API ?
REST stands for REpresentational State Transfer.
It means when a RESTful API is called, the server will transfer to the client a representation of the state of the requested resource.
REST APIs provide a flexible,lightweight way to integrate applications and have emerged as the most common method for connecting components in microservices.
and
REST is a software architectural style which uses a subset of HTTP
RESTful APIs relies on HTTP verbs to perform four operations :
The GET (to read a resource), POST (to create a resource),PUT(update a resource) and DELETE (to delete a resource)
RESTful APIs are defined with the following aspects :
1- A base URI, such as http://api.example.com/;
2- Standard HTTP methods (e.g., GET, POST, PUT, and DELETE);
3- Media types, such as application/json.
What is an API?
An application programming interface (API) is a connection between computers or between computer programs.
Application programming interfaces, or APIs, simplify software development and innovation by enabling applications to exchange data and functionality easily and securely
An API is a set of defined rules that explain how computers or applications communicate with one another. APIs sit between an application and the web server, acting as an intermediary layer that processes data transfer between systems.
Here’s how an API works:
1- A client application initiates an API call to retrieve information—also known as a request. This request is processed from an application to the web server via the API’s Uniform Resource Identifier (URI) and includes a request verb, headers, and sometimes, a request body.
2- After receiving a valid request, the API makes a call to the external program or web server.
3-The server sends a response to the API with the requested information.
4-The API transfers the data to the initial requesting application.
While the data transfer will differ depending on the web service being used, this process of requests and response all happens through an API. Whereas a user interface is designed for use by humans, APIs are designed for use by a computer or application..
NOTE--> A well defined REST API is similar to a website running in a web browser with built in HTTP functionality
Explain how Spring and JEE works?
UI Layer(User Interface Layer)-
Its what users interact with directly.Everything we see hear or touch.
Bussiness/Service Layer-
portion of application wedged between presentaion(what user sees) and data(what application depends on).
Data Access Layer-
Collections of classes,interfaces and their methods and properties that are used to perform CRUD(Create,Read,Update and Delete)
Database-
stores data
Product Controller- (to request/acccess services) UI Layer
Product Service- (for bussiness logic) Bussiness Layer
Data Access Layer- to access database
Database- stores data
What are spring modules?
The Spring framework comprises of many modules such as
Core, Beans, Context, Expression language, AOP, Aspects, Instrumentation, JDBC, ORM, OXM, JMS, Transaction, Web, Servlet, Struts etc.
These modules are grouped into Test, Core Container, AOP, Aspects, Instrumentation, Data Access / Integration, Web (MVC / Remoting)
Image 4 - @Image Credits- javatpoint
Image 5 - @Image Credits- java4s.com
Spring Core fundamentals
The Spring Core container contains core, beans, context and expression language (EL) or spEL(spring Expression Laungages)modules.
1--Core and Beans(fundamentals of spring core)
These modules provide IOC and Dependency Injection features.
2--Context
comes from bean plug other things
J2EE features
3-Spring Expression Laungages-
Query
object graph at runtime
JSP Extension
OTHER MODULES
AOP(Aspect Oriented Programming)
AOP contains Aspect,Instrumentstion and Messaging modules.
These modules support aspect oriented programming implementation where you can use Advices, Pointcuts etc. to decouple the code.
The aspects module provides support to integration with AspectJ.
The instrumentation module provides support to class instrumentation and classloader implementations.
Data Access / Integration
This group comprises of JDBC, ORM, OXM, JMS and Transaction modules. These modules basically provide support to interact with the database.
JDBC- for accessing database
ORM- provides integration layer hibernate features with orm
JMS- Java Messaging features- for producing and consuming messages
OXM- provides abstarct interface- object xml mapping
Web
This group comprises of Web, Web-Servlet, Web-Struts and Web-Portlet. These modules provide support to create web application.
What is maven project?
Maven is an automation and management tool developed by Apache Software Foundation.
It is written in Java Language to build projects written in C#, Ruby, Scala, and other languages.
It allows developers to create projects, dependency, and documentation using Project Object Model and plugins.
SPRING MVC
What does mvc stands for ?
MVC- Model View Controller
We can configure our spring project in two ways-
1- xml file
2- annotations
Spring MVC uses xml file.
Instead of downloading jar file to work with in our IDE what we do is we use maven dependencies in our xml file that we obtain from maven repostory.
This makes our job a lot easier,convenient and flexible.
How does Spring mvc works?
Spring MVC gives us front controller(Dispatcher Servlet)
DispatcherServlet acts as front controller for Spring based web applications. It provides a mechanism for request processing where actual work is performed by configurable, delegate components.
It is inherited from javax.servlet.http.HttpServlet, it is typically configured in the web.xml file.
It works in this manner
Client sends request to web.xml which sends request to Dispatcher Servlet.
Comments
Post a Comment