Last updated by admin 9 years ago

Advanced Topics

Grails Artifacts

Grails takes the separation of concerns approach splitting a Grails application in three layers or tiers:

  • web tier: presentation logic resides here. Artifacts are:
  • business logic tier: business logic controlled by a middle tier that supports transactional demarcation. Artifacts are:
  • persistence tier: operates within the transactional boundries of the business tier and is also controlled by a middle tier, deals with persistence details. Artifacts are:
    • domain class persistence methods
    • data sources
    • ORM tool sessions and factories.
Grails requires users to provide some of the artifacts in the above list. Configuration of these artifacts is taken care of by Grails based on a number of conventions per artifact type.

Injection behavior

Whenever injection of beans is supported the default behaviour is injection by name.

CountryService countryService
In this example a bean named "countryService"is required.

To enable injection by type add a "byName" property to the class and set it to false:

boolean byName = false
In the example above this would require a bean of type CountryService.

The reason for autowire by name being the default is that

def messageSource
results in an error from Spring saying that it can't autowire by type because there are 4384 beans of type java.lang.Object

When beans should not be available for injection create an "available" property and set it false. This property can be used to avoid type conflicts.

boolean available = true

Configurational properties

When property names are reserved for the configuration of specific artifacts in Grails other properties with the same name but not the same type are ignored.

class SomeService {
    boolean transactional = false
    String transactional = "false" // this property is ignored for configurational purposes.