As well as the
Web layer, Grails defines the notion of a service layer. The Grails team discourages the embedding of core application logic inside controllers, as it does not promote re-use and a clean separation of concerns.
Services in Grails are seen as the place to put the majority of the logic in your application, leaving controllers responsible for handling request flow via redirects and so on.
Creating a Service
You can create a Grails service by running the
create-service command from the root of your project in a terminal window:
grails create-service simple
The above example will create a service at the location
grails-app/services/SimpleService.groovy
. A service's name ends with the convention
Service
, other than that a service is a plain Groovy class: