Grails Executor插件出错,找不到bean“persistenceInterceptor”

时间:2011-12-08 16:14:44

标签: grails asynchronous groovy concurrency executor

我在我的Grails应用程序中安装了“executor”插件来进行一些简单的异步处理;我没有使用Hibernate或任何花哨的持久性。根据插件的文档(可在此处https://github.com/basejump/grails-executor找到),设置非常简单,只需将以下内容添加到resources.groovy,我应该很高兴...

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

我还没有尝试在我的代码中使用任何异步构造,但是当我启动我的grails应用程序时,我看到以下错误...

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

错误是有道理的,因为我没有在persistenceInterceptor中连接任何名为resources.groovy的bean,但是根据我不需要的插件文档。我是否必须编写一个实现PersistenceContextInterceptor接口的groovy类,并将其连接为“persistenceInterceptor”bean?在文档的“设置”部分中,没有提及此..

3 个答案:

答案 0 :(得分:1)

我想出来了......

执行者插件配置引用了persistenceInterceptor,因此一旦将插件添加到Grails项目中,您的代码必须在resources.groovy中连接PersistenceContextInterceptor的实例。我嘲笑了一个类来实现接口只是为了解决这个问题,而且它运行良好。

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

答案 1 :(得分:0)

实际上,设置并不要求您向resources.groovy添加任何内容 - 从文档中,该代码块已经是默认值。我建议从resources.groovy中删除所有自定义代码,除非您需要覆盖默认值并创建自定义线程池。

  

该插件设置了一个名为executorService的Grails服务bean,因此您无需执行任何操作。它委托Java ExecutorService的实现(不要与Grails服务混淆)接口,因此请阅读有关您可以使用executorService执行的操作的更多信息。它基本上包装了另一个线程池ExecutorService。默认情况下,它使用java Executors实用程序类来设置注入的线程池ExecutorService实现。默认的Grails executorService配置如下所示

答案 2 :(得分:-1)

我相信还有更合适的解决方案。尝试在 resources.groovy 文件中添加以下行:

springConfig.addAlias 'persistenceInterceptor', 'mongoPersistenceInterceptor'
相关问题