Advantage
• Separate roles - The Spring MVC separates each role, where the model object, controller, command object,
view resolver, DispatcherServlet, validator, etc. can be fulfilled by a specialized object.
• Light-weight - It uses light-weight servlet container to develop and deploy your application.
• Powerful Configuration - It provides a robust configuration for both framework and application classes
that includes easy referencing across contexts, such as from web controllers to business objects and
validators.
• Rapid development - The Spring MVC facilitates fast and parallel development.
• Reusable business code - Instead of creating new objects, it allows us to use the existing business objects.
• Easy to test - In Spring, generally we create JavaBeans classes that enable you to inject test data using the
setter methods.
• Flexible Mapping - It provides the specific annotations that easily redirect the page.
Advantage(Components)
• Inversion Of Control (IOC): In Spring Framework, loose coupling is achieved using Inversion of Control.
The objects give their own dependencies instead of creating or looking for dependent objects.
• Aspect Oriented Programming (AOP): By separating application business logic from system services,
Spring Framework supports Aspect Oriented Programming and enables cohesive development.
• Container: Spring Framework creates and manages the life cycle and configuration of application objects.
• Transaction Management: For transaction management, Spring framework provides a generic abstraction
layer. It is not tied to J2EE environments and it can be used in container-less environments.
• JDBC Exception Handling: The JDBC abstraction layer of the Spring Framework offers an exception
hierarchy, which simplifies the error handling strategy.
• MVC Framework: Spring Framework is a MVC web application framework. This framework is configurable
via interfaces and accommodates multiple view technologies.
Spring MVC Taxonomy
 DispatcherServlet
 Spring provided front controller
 Controls request routing
 Controllers
 User created POJO
 Standard Spring beans
 View
 Responsible for rendering a response
Core MVC components
 ModelAndView
 stores model data
 associates a view to the request
 can be a view implementation or a logical name
 ViewResolver
 Used to map logical view names to view implementations
 HandlerMapping
 Used by DispatcherServlet to map requests to controllers
Dispatcher Servlet
• Used to handle all incoming requests and route them through Spring
• Uses customizable logic to determine which controllers should handle which
requests
• Forwards all responses to through view handlers to determine the correct
views to route responses
• Exposes all beans defined in Spring to controllers for dependency injection
Model
• A Model is used in Spring MVC to pass objects from the controller tier up
into the view
• A Model is really just a java.util.Map
• You can add attributes to a Model and they will be put on the request as
attributes and available in the applications PageContext .
• In Spring you can simply pass back a Map orone of two Spring specific
classes; ModelMap or Model
Spring Views
 Extensive Support
 JSP, Velocity, FreeMarker, JasperReporters
 PDF, Excel
 Views are mapped by ViewResolvers
Spring MVC Annotations
 @Controller
 Stereotype used to “Controller” of MVC
 Scanned for RequestMappings
 Convention over configuration
 @RequestMapping
 Annotates a handler method for a request
 Very flexible
 @RequestParam
 Annotates that a method parameter should be bound to a web request parameter
 @SessionAttributes
 Marks session attributes that a handler uses
Spring MVC Parameters
 Parameters can be
 Request / response / session
 WebRequest
 InputStream
 OutputStream
 @RequestParam etc..
Spring MVC Return Types
 Return types
 ModelAndView Object
 Model Object
 Map for exposing model
 View Object
 String which is a view name
 Void… if method wrote the response content directly
Handler Mappings
 DefaultAnnotationHandlerMapping
 annotation based - @Controller
 SimpleUrlHandlerMapping
 configuration based
 still works with annotations
 ControllerClassNameHandlerMapping
 UrlFileNameViewController
 views without a controller
Spring mvc
Spring mvc
Spring mvc
Spring mvc
Spring mvc
Spring mvc

Spring mvc

  • 2.
    Advantage • Separate roles- The Spring MVC separates each role, where the model object, controller, command object, view resolver, DispatcherServlet, validator, etc. can be fulfilled by a specialized object. • Light-weight - It uses light-weight servlet container to develop and deploy your application. • Powerful Configuration - It provides a robust configuration for both framework and application classes that includes easy referencing across contexts, such as from web controllers to business objects and validators. • Rapid development - The Spring MVC facilitates fast and parallel development. • Reusable business code - Instead of creating new objects, it allows us to use the existing business objects. • Easy to test - In Spring, generally we create JavaBeans classes that enable you to inject test data using the setter methods. • Flexible Mapping - It provides the specific annotations that easily redirect the page.
  • 3.
    Advantage(Components) • Inversion OfControl (IOC): In Spring Framework, loose coupling is achieved using Inversion of Control. The objects give their own dependencies instead of creating or looking for dependent objects. • Aspect Oriented Programming (AOP): By separating application business logic from system services, Spring Framework supports Aspect Oriented Programming and enables cohesive development. • Container: Spring Framework creates and manages the life cycle and configuration of application objects. • Transaction Management: For transaction management, Spring framework provides a generic abstraction layer. It is not tied to J2EE environments and it can be used in container-less environments. • JDBC Exception Handling: The JDBC abstraction layer of the Spring Framework offers an exception hierarchy, which simplifies the error handling strategy. • MVC Framework: Spring Framework is a MVC web application framework. This framework is configurable via interfaces and accommodates multiple view technologies.
  • 7.
    Spring MVC Taxonomy DispatcherServlet  Spring provided front controller  Controls request routing  Controllers  User created POJO  Standard Spring beans  View  Responsible for rendering a response
  • 8.
    Core MVC components ModelAndView  stores model data  associates a view to the request  can be a view implementation or a logical name  ViewResolver  Used to map logical view names to view implementations  HandlerMapping  Used by DispatcherServlet to map requests to controllers
  • 9.
    Dispatcher Servlet • Usedto handle all incoming requests and route them through Spring • Uses customizable logic to determine which controllers should handle which requests • Forwards all responses to through view handlers to determine the correct views to route responses • Exposes all beans defined in Spring to controllers for dependency injection
  • 10.
    Model • A Modelis used in Spring MVC to pass objects from the controller tier up into the view • A Model is really just a java.util.Map • You can add attributes to a Model and they will be put on the request as attributes and available in the applications PageContext . • In Spring you can simply pass back a Map orone of two Spring specific classes; ModelMap or Model
  • 11.
    Spring Views  ExtensiveSupport  JSP, Velocity, FreeMarker, JasperReporters  PDF, Excel  Views are mapped by ViewResolvers
  • 12.
    Spring MVC Annotations @Controller  Stereotype used to “Controller” of MVC  Scanned for RequestMappings  Convention over configuration  @RequestMapping  Annotates a handler method for a request  Very flexible  @RequestParam  Annotates that a method parameter should be bound to a web request parameter  @SessionAttributes  Marks session attributes that a handler uses
  • 13.
    Spring MVC Parameters Parameters can be  Request / response / session  WebRequest  InputStream  OutputStream  @RequestParam etc..
  • 14.
    Spring MVC ReturnTypes  Return types  ModelAndView Object  Model Object  Map for exposing model  View Object  String which is a view name  Void… if method wrote the response content directly
  • 15.
    Handler Mappings  DefaultAnnotationHandlerMapping annotation based - @Controller  SimpleUrlHandlerMapping  configuration based  still works with annotations  ControllerClassNameHandlerMapping  UrlFileNameViewController  views without a controller

Editor's Notes

  • #13 Convention over configuration=attempts to decrease the number of decisions
  • #18 <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </init-param>
  • #19 @controller class
  • #20 Spring-servlet.xml