18.1 The Underpinnings of Grails - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.0.12
18.1 The Underpinnings of Grails
Grails is actually a Spring MVC application in disguise. Spring MVC is the Spring framework's built-in MVC web application framework. Although Spring MVC suffers from some of the same difficulties as frameworks like Struts in terms of its ease of use, it is superbly designed and architected and was, for Grails, the perfect framework to build another framework on top of.Grails leverages Spring MVC in the following areas:- Basic controller logic - Grails subclasses Spring's DispatcherServlet and uses it to delegate to Grails controllers
- Data Binding and Validation - Grails' validation and data binding capabilities are built on those provided by Spring
- Runtime configuration - Grails' entire runtime convention based system is wired together by a Spring ApplicationContext
- Transactions - Grails uses Spring's transaction management in GORM
The Grails ApplicationContext
Spring developers are often keen to understand how the GrailsApplicationContext
instance is constructed. The basics of it are as follows.
- Grails constructs a parent
ApplicationContext
from theweb-app/WEB-INF/applicationContext.xml
file. ThisApplicationContext
configures the GrailsApplication instance and the GrailsPluginManager. - Using this
ApplicationContext
as a parent Grails' analyses the conventions with theGrailsApplication
instance and constructs a childApplicationContext
that is used as the rootApplicationContext
of the web application
Configured Spring Beans
Most of Grails' configuration happens at runtime. Each plugin may configure Spring beans that are registered in theApplicationContext
. For a reference as to which beans are configured, refer to the reference guide which describes each of the Grails plugins and which beans they configure.