## 14.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 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 onto 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

In other words Grails has Spring embedded running all the way through it.

#### The Grails ApplicationContext

Spring developers are often keen to understand how the Grails `ApplicationContext` instance is constructed. The basics of it are as follows.

- Grails constructs a parent `ApplicationContext` from the `web-app/WEB-INF/applicationContext.xml`. This `ApplicationContext` sets up the api:org.codehaus.groovy.grails.commons.GrailsApplication instance and the api:org.codehaus.groovy.grails.plugins.GrailsPluginManager.
- Using this `ApplicationContext` as a parent Grails' analyses the conventions with the `GrailsApplication` instance and constructs a child `ApplicationContext` that is used as the root `ApplicationContext` of the web application

#### Configured Spring Beans

Most of Grails' configuration happens at runtime. Each plug-in may configure Spring beans that are registered with the `ApplicationContext`. For a reference as to which beans are configured refer to the reference guide which describes each of the Grails plug-ins and which beans they configure.