views:

80

answers:

1

Hi,

In a Grails application I would like to add a foo() method to all my controller classes. I know that I can do this inside a plugin's doWithDynamicMethods closure using code like:

application.controllerClasses.toList()*.metaClass*.foo = { println 'foo called' }

However, I don't want to create a plugin just for this purpose. Is there anywhere else I can do this. I suspect it might be possible within the init closure of BootStrap.groovy, but I don't know how to get access to the GrailsApplication instance in this closure.

Thanks, Don

+2  A: 
def grailsApplication = org.codehaus.groovy.grails.commons.ApplicationHolder.application
Siegfried Puchbauer