raffian raffian - 1 year ago 70
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

and I should be good to go...

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
, 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 Source

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.

 persistenceInterceptor(  com.cache.DefaultCacheInterceptor){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download