class BookController {
static scope = "session"
// ...
}
scope
Purpose
Changes the scope of a controller
Examples
Description
Unless specified by the grails.controllers.defaultScope
property in application.yml
, controllers are by default "prototype"-scoped which means that a new controller will be created for each request.
The scope can be set for an individual controller by specifying a static scope
attribute with one of the following values:
-
prototype
(default) - A new controller will be created for each request (recommended for actions as Closure properties) -
session
- One controller is created for the scope of a user session -
singleton
- Only one instance of the controller ever exists (recommended for actions as methods)
Newly created applications have the grails.controllers.defaultScope config property set to a value of "singleton" in application.yml .
|
See Controllers and Scopes in the user guide for more information.