Last updated by mauk81 2 years ago

Spring MVC Integration

Grails uses Spring MVC as the underlying web application framework. Spring MVC might not be the simplest framework to use but it is most definitely one of the most extensible making it perfect for Grails. The Grails servlet extends Spring's DispatcherServlet to bootstrap the Grails environment, there is then a single Spring MVC controller called org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController that handles all Grails controller requests.

The SimpleGrailsController delegates to a class called org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper that actually handles the request. This class breaks the handling of the request down into a number of steps. The entry point for the class is the {{handleUri}} method which:

  1. Parses the URI into its components (controller name, action name, id etc.)
  2. Looks up a GrailsControllerClass instance for the URI
  3. Creates a new Grails controller instance
  4. Configures the controller instance's dynamic methods and properties
  5. Retrieves a scaffolder if is scaffolding is enabled for the controller
  6. Gets a reference to the closure action to execute for the URI
  7. Increments flash scope moving it on to its next state
  8. Gets the view name for the URI
  9. Executes any before inteceptors registered
  10. Executes the closure that is the controller action if the before interceptor didn't return false
  11. Creates a Spring MVC ModelAndView instance from the view name and the model returned by the closure action
  12. Executes any after interceptors registered passing returned model
  13. Returns the Spring MVC ModelAndView instance