0

I have created custom event listener that extends AbstractPersistenceEventListener as described in the Grails docs http://grails.org/doc/latest/guide/GORM.html and it works fine, however. i am unable to inject Service in this listener if doing as follows.

    def context = ServletContextHolder.servletContext.getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT)
def myService = context.myService 

The 'context' returns null.

Any ideas what may be the problem. Thank You p.s. GRails 2.1.2

latvian
  • 3,161
  • 9
  • 33
  • 62

1 Answers1

1

Pass in applicationContext to your Listener as a constructor argument when you register it.

Todd Murray
  • 423
  • 2
  • 7
  • Thank you Todd. i was confused for little bit...in so much Magic:) Instead of argument, i keep the constructor as is and assign service after initiation before registering event. – latvian Apr 19 '13 at 02:02
  • def doWithApplicationContext = { applicationContext -> application.mainContext.eventTriggeringInterceptor.datastores.each { k, datastore -> def cacheListener = new CacheListener(datastore) cacheListener.nodeDriverProxyService = applicationContext.nodeDriverProxyService applicationContext.addApplicationListener cacheListener – latvian Apr 19 '13 at 02:02