{"id":1885,"date":"2016-10-12T14:50:36","date_gmt":"2016-10-12T14:50:36","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1885"},"modified":"2019-04-08T12:50:20","modified_gmt":"2019-04-08T12:50:20","slug":"how-spring-works","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-spring-works\/","title":{"rendered":"How Spring MVC Works"},"content":{"rendered":"<p>Spring MVC uses 2 design Patterns Internally<\/p>\n<ol>\n<li>Front Controller<\/li>\n<li>MVC<\/li>\n<\/ol>\n<p><strong>How Spring MVC Handles Request<\/strong><\/p>\n<ol>\n<li>Receive the request from client<\/li>\n<li>Consult Handle Mapper  to decide which controller processes the request<\/li>\n<li>Dispatch the request to the controller <\/li>\n<li>Controller processes the request and returns the logical view name and model back to DispatcherServlet<\/li>\n<li>Consult View Resolver for appropriate View for the logical view name from Controller<\/li>\n<li>Pass the model to View implementation for rendering<\/li>\n<li>View renders the model and returns the result to DispatcherServlet<\/li>\n<li>Return the rendered result from view to the client<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2016\/10\/Spring-Flow.jpg\" alt=\"\" height=\"762\" width=\"725\"\/><\/p>\n<p><strong>MappingHandler<\/strong><br \/>\nDispatcherServlet uses MappingHandler to find out which controller is right one for this request.There are many MappingHandler implementations which uses different strategies to map the request to Controller.   By default DispatcherServlet will use <strong>BeanNameUrlHandlerMapping <\/strong>and <strong>DefaultAnnotationHandlerMapping<\/strong>.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic interface HandlerMapping \r\n{\r\n      HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception;\r\n}\r\n<\/pre>\n<p><strong>ViewResolver<\/strong><br \/>\nWith the help of ViewResolver strategy object DispatcherServlet can find out physical view from the logical view name.   Similar to MappingHandler there are also many different strategies  for resolving the view based on the different view technologies.    Most commonly used implementation of ViewResolver is <strong>InternalResourceViewResolver<\/strong>.  <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic interface ViewResolver \r\n{\r\n      View resolveViewName(String viewName, Locale locale) throws Exception;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Spring MVC uses 2 design Patterns Internally Front Controller MVC How Spring MVC Handles Request Receive the request from client Consult Handle Mapper to decide which controller processes the request Dispatch the request to the controller Controller processes the request and returns the logical view name and model back to DispatcherServlet Consult View Resolver for&hellip; <a href=\"https:\/\/codethataint.com\/blog\/how-spring-works\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[253],"class_list":["post-1885","post","type-post","status-publish","format-standard","hentry","category-spring-mvc","tag-interview"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1885","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1885"}],"version-history":[{"count":7,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1885\/revisions"}],"predecessor-version":[{"id":1991,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1885\/revisions\/1991"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}