Hooking into Grails event in order to inject properties and methods without beeing af Plugin
I have some custom groovy classes in my Grails project, and I would like to inject a logger and some other stuff into the class, like it works in a Service class or Co开发者_Go百科ntroller class. The code in the "target" class would in this way have direct access to logging without further ado.
How would it be possible to write scripts to hook into events in the "doWithDynamicMethods" style in a Grails project (as opposed to a Grails Plugin) and in this way enhance your own classes?
Thanks,
Christian Sonne Jensen
In an application, typically you would do this in grails-app/conf/BootStrap.groovy, e.g.
class BootStrap {
def init = { servletContext ->
Foo.metaClass.getLog = { -> ... }
}
}
精彩评论