在Grails的GORM中添加更改侦听器

pab*_*car 1 grails grails-orm grails-2.0

我是Grails的新手,我正在使用Grails 2.0.1.我想为域类的对象中的更改添加持久性事件侦听器,因此我尝试了用户指南中给出的Bootstrap.groovy中的代码:

def init = {
    applicationContext.addApplicationListener(new FooBarListener())
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

错误context.GrailsContextLoader - 执行bootstraps时出错:没有这样的属性:类的applicationContext:BootStrap

如何从BootStrap类中获取applicacionContext属性?或者文档是否过时,是否有新的/更好的方法来添加域更改侦听器?

提前致谢.

Bur*_*ith 8

我知道的最短路是

class BootStrap {

   def grailsApplication

   def init = { servletContext ->
      def applicationContext = grailsApplication.mainContext
   }
}
Run Code Online (Sandbox Code Playgroud)