Thursday, 1 February 2018

Spring MVC Architecture

Spring mvc architecture, follow of spring mvc architecture,Spring MVC execution flow, execution flow of spring mvc,

thirdparty image

Execution flow:-
  • Client sends an HTTP request to a specific URL
  • DispatcherServlet of Spring MVC receives the request
  • It passes the request to a specific controller depending on the URL requested using @Controller and @RequestMapping annotations.
  • Spring MVC Controller then returns a logical view name and model to DispatcherServlet.
  • DispatcherServlet consults view resolvers until actual View is determined to render the output
  • DispatcherServlet contacts the chosen view (e.g. Freemarker, JSP) with model data and it renders the output depending on the model data
  • The rendered output is returned to the client as response

ü  You should Configure DispatcherServlet in web.xml as following..

<servlet>     
 <servlet-name>spring</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <load-on-startup>1</load-on-startup>  
</servlet>  
<servlet-mapping>  
    <servlet-name>spring</servlet-name>  
    <url-pattern>*.html</url-pattern>  
</servlet-mapping>

ü  At web container startup.
·         DispatcherServlet will be loaded , Instantiated and initialized by calling init() method.
·         Init() method of DispatcherServlet will try to identify the Spring Configuration Document with following naming conversions.

Servlet_name-servlet.xml
Ex:
Dashzin-servlet.xml

ü  DispatcherServlet create the ApplicationContext (XmlWebApplicationContext) object by reading all the beans specified in the Spring Configuration Document.
ü  If Spring Configuration Document is not found with the given naming conversion then ApplicationContext object will not be created by the DispatcherServlet.

Example:-

Public class DispatcherServlet extends HttpServlet{
ApplicationContext ctx=null;
Public void init(ServletConfig cfg){
// try  to get the spring Configuration Documents with the default naming conversions
String xml=”Dashzin”+”-servlet.xml”;
// if found then create the ApplicationContext object
Ctx=new XmlWebApplicationContext(xml);
}
……
}

After Deploying and starting SpringMVC based web application , following tasks will happen at web Container start-up.

ü  Web Container loads, create and initialize DispatcherServlet by calling init() method.
ü  DispatcherServlet’s init() performs the following:-
·         Identifies spring configuration document file
·         Spring Container instance will be created by reading all the beans from identified spring configuration document  
·         Initializes the DispatcherServlet with spring container instances

Following task will happen at Web Container shutdown-time

ü  Web container call destroy() method of DispatcherServlet.
ü  destroy() method of DispatcherServlet destroys the spring container instance.






DashZin

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

30 comments:

  1. <a href="https://zahretelmamlakah.com/%d8%b4%d8%b1%d9%83%d8%a9-%d8%b9%d8%b2%d9%84-%d8%ae%d8%b2%d8%a7%d9%86%d8%a7%d8%aa-%d8%a8%d8%ae%d9%85%d9%8a%d8%b3-%d9%85%d8%b4%d9%8a

    ReplyDelete