SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Spring MVC
Presentation by
Hung Nguyen Huy
Content
1. HTTP Servlet (Review)
2. What is Spring MVC?
3. MVC Architecture
4. Request Processing Workflow in Spring MVC
5. Spring Web Application Context
6. Spring MVC Configuration
7. Important Annotations
8. Summary
HTTP Servlet (Review)
HTTP Servlets
● Are Java classes that run on Web
Servers to dynamically process HTTP
requests and construct HTTP
responses.
● Deployed inside a Servlet Container
which run on a Web Server.
● Tomcat is a popular Servlet Container.
Servlets Architecture
● Servlets act as a middle layer between a
Web browser and databases or
applications on the Web Server.
● The following diagram shows the
position of Servlets in a Web Application
What is Spring MVC ?
What is Spring MVC?
Modules of Spring Framework on the Web layer:
● Web module provides basic web-oriented integration
features and the initialization of the IoC container
using servlet listeners and a web application context.
● Servlet module contains Spring MVC
implementation for web applications.
What is Spring MVC ? (cont.)
● A web framework built on the Servlet API.
● Provides Model-View-Controller (MVC) architecture and ready
components that can be used to develop flexible and loosely coupled web
applications.
● Request-driven, designed around a central Servlet that dispatches
requests to controllers - the DispatcherServlet.
MVC
MVC (Model-View-Controller)
Introduced by Trygve Reenskaug at Xerox Parc in 1979.
MVC (Model-View-Controller)
● An architectural pattern commonly used
for developing user interfaces.
● An application is divided into 3
interconnected parts:
○ Model - Responsible for managing data
of the application.
○ View - Responsible for displaying the
model data to user.
○ Controller - Responsible for processing
user requests and building an
appropriate model and passes it to the
view for rendering.
Request Processing Workflow
in Spring MVC
Request Processing Workflow (High Level)
The request processing workflow in Spring Web MVC (high level)
DispatcherServlet
● Spring MVC is designed around a central
servlet named DispatcherServlet.
● DispatcherServlet acts as a central entry
point to the Spring MVC application.
● Every request is handled by
DispatcherServlet.
● DispatcherServlet is an expression of
the Front Controller pattern.
The request processing workflow in Spring Web MVC (high level)
Controllers
● The Front Controller’s job is to
determine a suitable handler capable of
performing the actual processing.
● Handlers are Spring MVC Controllers.
● The selected Controller interacts with
the service layer; the relevant data are
collected in a model.
● When the Controller has finished
processing, the Front Controller
determines which view to render.
The request processing workflow in Spring Web MVC (high level)
View
● When the Controller has finished
processing, the Front Controller
determines which view to render.
● The Front Controller passes the model
to the view which is finally which is
finally rendered on the browser.
The request processing workflow in Spring Web MVC (high level)
Request Processing Workflow (Details Level)
1. DispatcherServlet receives the request.
2. DispatcherServlet dispatches the task of selecting an
appropriate controller to HandlerMapping. HandlerMapping
selects the Controller which is mapped to the incoming request
URL and returns the (selected Handler) and Controller to
DispatcherServlet.
3. DispatcherServlet dispatches the task of executing of business
logic of Controller to HandlerAdapter.
4. HandlerAdapter calls the business logic process of Controller.
5. Controller executes the business logic, sets the processing
result in Model and returns the logical name of view to
HandlerAdapter.
6. DispatcherServlet dispatches the task of resolving the View
corresponding to the View name to ViewResolver.
ViewResolver returns the View mapped to View name.
7. DispatcherServlet dispatches the rendering process to
returned View.
8. View renders Model data and returns the response.
Web Application Context
Web Application Context
● DispatcherServlet expects a WebApplicationContext,
an extension of a plain ApplicationContext, for its own
configuration.
● WebApplicationContext has a link to the
ServletContext and Servlet it is associated with.
● The root WebApplicationContext typically contains
infrastructure beans such as data repositories and
business services which are inherited and could be
overridden in the Servlet WebApplicationContext.
● Servlet WebApplicationContext contains web-related
beans: such as controllers, handler mappings,...
Spring MVC Configurations
Spring MVC Configurations
Spring MVC supports 2 type of configurations:
● XML Configuration
● Java-based Configuration
Important annotations
Important annotations
Some important annotations which are used in a Spring MVC application.
● @Controller and @RestController
● @RequestMapping
○ @GetMapping, @PostMapping, @PutMapping and @DeleteMapping
● @RequestParam, @PathVariable
● @RequestBody
● @ResponseBody
Summary

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Web api
Web apiWeb api
Web api
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring boot
Spring bootSpring boot
Spring boot
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 

Semelhante a Spring MVC Framework

Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desaijinaldesailive
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Naresh Chintalcheru
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcquickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcjorgesimao71
 
Lecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdfLecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdfLê Thưởng
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxAbhijayKulshrestha1
 
Spring mvc
Spring mvcSpring mvc
Spring mvcHui Xie
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3Ilio Catallo
 

Semelhante a Spring MVC Framework (20)

Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Mvc
MvcMvc
Mvc
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
quickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvcquickguide-einnovator-7-spring-mvc
quickguide-einnovator-7-spring-mvc
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
Lecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdfLecture 05 - Creating a website with Razor Pages.pdf
Lecture 05 - Creating a website with Razor Pages.pdf
 
Unit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptxUnit 38 - Spring MVC Introduction.pptx
Unit 38 - Spring MVC Introduction.pptx
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Dispatcher
DispatcherDispatcher
Dispatcher
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 

Último

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 

Último (20)

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Spring MVC Framework

  • 2. Content 1. HTTP Servlet (Review) 2. What is Spring MVC? 3. MVC Architecture 4. Request Processing Workflow in Spring MVC 5. Spring Web Application Context 6. Spring MVC Configuration 7. Important Annotations 8. Summary
  • 4. HTTP Servlets ● Are Java classes that run on Web Servers to dynamically process HTTP requests and construct HTTP responses. ● Deployed inside a Servlet Container which run on a Web Server. ● Tomcat is a popular Servlet Container.
  • 5. Servlets Architecture ● Servlets act as a middle layer between a Web browser and databases or applications on the Web Server. ● The following diagram shows the position of Servlets in a Web Application
  • 7. What is Spring MVC? Modules of Spring Framework on the Web layer: ● Web module provides basic web-oriented integration features and the initialization of the IoC container using servlet listeners and a web application context. ● Servlet module contains Spring MVC implementation for web applications.
  • 8. What is Spring MVC ? (cont.) ● A web framework built on the Servlet API. ● Provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications. ● Request-driven, designed around a central Servlet that dispatches requests to controllers - the DispatcherServlet.
  • 9. MVC
  • 10. MVC (Model-View-Controller) Introduced by Trygve Reenskaug at Xerox Parc in 1979.
  • 11. MVC (Model-View-Controller) ● An architectural pattern commonly used for developing user interfaces. ● An application is divided into 3 interconnected parts: ○ Model - Responsible for managing data of the application. ○ View - Responsible for displaying the model data to user. ○ Controller - Responsible for processing user requests and building an appropriate model and passes it to the view for rendering.
  • 13. Request Processing Workflow (High Level) The request processing workflow in Spring Web MVC (high level)
  • 14. DispatcherServlet ● Spring MVC is designed around a central servlet named DispatcherServlet. ● DispatcherServlet acts as a central entry point to the Spring MVC application. ● Every request is handled by DispatcherServlet. ● DispatcherServlet is an expression of the Front Controller pattern. The request processing workflow in Spring Web MVC (high level)
  • 15. Controllers ● The Front Controller’s job is to determine a suitable handler capable of performing the actual processing. ● Handlers are Spring MVC Controllers. ● The selected Controller interacts with the service layer; the relevant data are collected in a model. ● When the Controller has finished processing, the Front Controller determines which view to render. The request processing workflow in Spring Web MVC (high level)
  • 16. View ● When the Controller has finished processing, the Front Controller determines which view to render. ● The Front Controller passes the model to the view which is finally which is finally rendered on the browser. The request processing workflow in Spring Web MVC (high level)
  • 17. Request Processing Workflow (Details Level) 1. DispatcherServlet receives the request. 2. DispatcherServlet dispatches the task of selecting an appropriate controller to HandlerMapping. HandlerMapping selects the Controller which is mapped to the incoming request URL and returns the (selected Handler) and Controller to DispatcherServlet. 3. DispatcherServlet dispatches the task of executing of business logic of Controller to HandlerAdapter. 4. HandlerAdapter calls the business logic process of Controller. 5. Controller executes the business logic, sets the processing result in Model and returns the logical name of view to HandlerAdapter. 6. DispatcherServlet dispatches the task of resolving the View corresponding to the View name to ViewResolver. ViewResolver returns the View mapped to View name. 7. DispatcherServlet dispatches the rendering process to returned View. 8. View renders Model data and returns the response.
  • 19. Web Application Context ● DispatcherServlet expects a WebApplicationContext, an extension of a plain ApplicationContext, for its own configuration. ● WebApplicationContext has a link to the ServletContext and Servlet it is associated with. ● The root WebApplicationContext typically contains infrastructure beans such as data repositories and business services which are inherited and could be overridden in the Servlet WebApplicationContext. ● Servlet WebApplicationContext contains web-related beans: such as controllers, handler mappings,...
  • 21. Spring MVC Configurations Spring MVC supports 2 type of configurations: ● XML Configuration ● Java-based Configuration
  • 23. Important annotations Some important annotations which are used in a Spring MVC application. ● @Controller and @RestController ● @RequestMapping ○ @GetMapping, @PostMapping, @PutMapping and @DeleteMapping ● @RequestParam, @PathVariable ● @RequestBody ● @ResponseBody