Last updated by mauk81 2 weeks ago

General Architecture

The commons package

The core Grails classes that make up the foundation of Grails can be found in the org.codehaus.groovy.grails.commons package. The classes within this package deal with the conventions and most implement the interface org.codehaus.groovy.grails.commons.GrailsClass which defines methods for retrieving various representations of the class name based on the convention.

The classes themselves are loaded into an instance of org.codehaus.groovy.grails.commons.GrailsApplication the default implementation for which can be found here.

The DefaultGrailsApplication class defines two constructors one which takes an array of Spring resources. The resources are a set of the set of .groovy files that resides within the grails-app directory and are loaded by the Spring applicationContext.xml file found in the WEB-INF directory. The DefaultGrailsApplication class also defines a constructor that takes an array of classes which is mainly used in test cases for example:

GroovyClassLoader gcl = new GroovyClassLoader();
    Class domainClass = gcl.parseClass("class Test { Long id; Long version; }" );
    Class controller = gcl.parseClass("class TestController { def list = {} }");
    GrailsApplication app = new DefaultGrailsApplication( new Class[] {
        domainClass, controller } );
The above code creates an GrailsApplication instance with a domain class called Test and a controller called TestController. The domain class is encapsulated by an instance of org.codehaus.groovy.grails.commons.GrailsDomainClass and the controller by an instance of org.codehaus.groovy.grails.commons.GrailsControllerClass

Utility Classes for the commons package

There are a number of utility classes for working with the commons package. The class org.codehaus.groovy.grails.commons.GrailsClassUtils provides methods for evaluating the conventions of classes and retrieving different naming representations. Since 0.5 these convention evaluation methods are removed and are available on GrailsApplication via the Developer - Artefact API. provides methods for working with Grails resources before they are loaded into classes (ie the .groovy files themselves and where they reside in the app structure).

The org.codehaus.groovy.grails.commons.GrailsResourceLoader class is an instance of groovy.lang.ResourceLoader. This class is set on the GroovyClassLoader instance and ensures that classes can be loaded from Spring Resource instances.