raffian raffian - 2 months ago 13
Groovy Question

Error with Grails Executor plugin, bean "persistenceInterceptor" not found

I installed the "executor" plugin into my Grails app to do some simple asynchronous processing; I'm not using Hibernate or any fancy persistence. Based on the documentation for the plugin, which can be found here https://github.com/basejump/grails-executor, the setup is very simple, just add the following to

resources.groovy
and I should be good to go...

//resources.groovy
executorService( PersistenceContextExecutorWrapper ) { bean->
bean.destroyMethod = 'destroy'
persistenceInterceptor = ref("persistenceInterceptor")
executor = Executors.newCachedThreadPool()
}


I have not yet tried to use any of the asynchronous constructs in my code, but when I start up my grails app I see the following error...

Cannot resolve reference to bean 'persistenceInterceptor' while setting bean property 'persistenceInterceptor';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'persistenceInterceptor' is defined


The error makes sense since in I have not wired up any bean named
persistenceInterceptor
in
resources.groovy
, but according to the plugin documentation I don't have to. Do I have to write a groovy class that implements the PersistenceContextInterceptor interface, and wire that up as the "persistenceInterceptor" bean? In the Setup section of the documentation, there is no mention of this..

Answer

I figured this out....

The persistenceInterceptor is referenced by the executor plugin configuration, so once you add the plugin to a Grails project, your code must wire up an instance of PersistenceContextInterceptor in resources.groovy. I mocked a class to implement the interface just to get around this for now, and it worked fine.

//resources.groovy
 persistenceInterceptor(  com.cache.DefaultCacheInterceptor){
}