Skip to content

Commit 6bb4de5

Browse files
committed
Ensure @resource generated controllers are not lazy
1 parent 52db932 commit 6bb4de5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ class ControllersGrailsPlugin extends Plugin {
155155
for (controller in application.getArtefacts(ControllerArtefactHandler.TYPE)) {
156156
log.debug "Configuring controller $controller.fullName"
157157
if (controller.available) {
158+
def lazyInit = controller.hasProperty("lazyInit") ? controller.getPropertyValue("lazyInit") : true
158159
"${controller.fullName}"(controller.clazz) { bean ->
159-
bean.lazyInit = true
160+
bean.lazyInit = lazyInit
160161
def beanScope = controller.getScope()
161162
bean.scope = beanScope
162163
bean.autowire = "byName"

grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/transform/ResourceTransform.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ class ResourceTransform implements ASTTransformation, CompilationUnitAware {
185185
final uri = uriAttr.getText()
186186
if(uri) {
187187
final urlMappingsClassNode = new ClassNode(UrlMappings).getPlainNodeReference()
188+
189+
final lazyInitField = new FieldNode('lazyInit', PUBLIC | STATIC | FINAL, ClassHelper.Boolean_TYPE,newControllerClassNode, new ConstantExpression(Boolean.FALSE))
190+
newControllerClassNode.addField(lazyInitField)
191+
188192
final urlMappingsField = new FieldNode('$urlMappings', PRIVATE, urlMappingsClassNode,newControllerClassNode, null)
189193
newControllerClassNode.addField(urlMappingsField)
190194
final urlMappingsSetterParam = new Parameter(urlMappingsClassNode, "um")

0 commit comments

Comments
 (0)