(Quick Reference)

19.1 The Underpinnings of Grails

Version: 3.2.8

19.1 The Underpinnings of Grails

Grails is actually a Spring Boot application in disguise. Spring Boot is the Spring framework’s built-in MVC web application framework. Although Spring Boot suffers from some difficulties in terms of its ease of use, it is superbly designed and architected. For Grails, it was the perfect framework to build another framework on top of.

Grails leverages Spring Boot 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

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 file. This ApplicationContext configures the GrailsApplication instance and the 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 plugin may configure Spring beans that are registered in the ApplicationContext. 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.