Question

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..

Was it helpful?

Solution

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){
}

OTHER TIPS

Actually the setup does not require that you add anything at all to resources.groovy - from the docs, that block of code is already the default. I would suggest removing all of your custom code from resources.groovy unless you need to override the defaults and create a custom threadpool.

The plugin sets up a Grails service bean called executorService so you need do nothing really. It delegates to an implementation of an Java ExecutorService (not to be confused with a Grails Service) interface so read up on that for more info on what you can do with the executorService. It basically wraps another thread pool ExecutorService. By default it uses the java Executors utility class to setup the injected thread pool ExecutorService implementation. The default Grails executorService config looks like this

I believe there is even more suitable solution. Try adding the following line in resources.groovy file:

springConfig.addAlias 'persistenceInterceptor', 'mongoPersistenceInterceptor'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top