Spring 3.0 MVC - Introduction By, Srinivas Reddy.S
Advantages of Spring 3.0 MVC Supports RESTful URLs. Annotation based configuration. Supports to plug with other MVC frameworks like Struts etc. Flexible in supporting different view types like JSP, velocity, XML, PDF etc.,
MVC – An overview Controller View Model Request Response
Front Controller
Front Controller - Responsiblities Initialize the framework to cater to the requests. Load the map of all the URLs and the components responsible to handle the request. Prepare the map for the views.
Spring 3 MVC- Basic Architecture Dispacther Servlet (Front controller) HandlerMapping (Map of URL and controllers) Controller (Responsible to handle request) View (JSP, XML, Velocity) Model (POJO) Request
Spring 3.0 MVC Request Flow DispatcherServlet Capture the Request Locale If request is multipart- File upload data is exposed HandlerMapping (Map of URL and controllers) Handler Chain Interceptor - Pre Process Interceptor - Pre Process Controller Interceptor - Post Process Interceptor - Post Process View Resolver Prepare the View Request Response
Spring 3 MVC Framework- Initialization Dispatcher Servlet - Initialization MultipartResolver LocaleResolver ThemeResolver HandlerMappings HandlerAdapters HandlerExceptionResolvers RequestToViewNameTranslator ViewResolvers
Important Intefaces InterfaceDefault bean namepurpose org.springframework.web.servlet. HandlerMapping handlerMappingMaps the Request to Handlers(Controllers) org.springframework.web.servlet. HandlerAdapter nonePlugs the other frameworks handlers org.springframework.web.servlet. ViewResolver viewResolverMaps the view names to view instances org.springframework.web.servlet. HandlerExceptionResolver handlerExceptionRes olver Mapping of the exceptions to handlers and views org.springframework.web.multip art. MultipartResolver multipartResolverInterface to handle the file uploads org.springframework.web.servlet. LocaleResolver localeResolverHelps to resolve the locale from the request org.springframework.web.servlet. ThemeResolver themeResolverResolves a theme for a Request.
Spring 3.0 MVC Configuration Step 1: – Configure the web.xml with DispatcherServlet and details of the application context file location. spring3 org.springframework.web.servlet.DispatcherServlet 1 spring3 *.*
Spring 3.0 MVC Configuration Step 2: – Configure the contextConfigLocation for the application context to be loaded contextConfigLocation /WEB-INF/spring3-service.xml org.springframework.web.context.ContextLoaderListener
Spring 3.0 MVC Configuration Step 3: Configure the spring3-servlet.xml <beans xmlns=" xmlns:xsi=" xmlns:context=" xsi:schemaLocation=" <context:component-scan base-package="com.java9s.web" /> <bean class="org.springframework.web.servlet.mvc.annotation. DefaultAnnotationHandlerMapping" /> <bean class="org.springframework.web.servlet.mvc.annotation. AnnotationMethodHandlerAdapter" />
Thank you visit