Grails-在Bootstrap.groovy中调用runAsync

Grails-在Bootstrap.groovy中调用runAsync,grails,groovy,executorservice,Grails,Groovy,Executorservice,我在Bootstrap.groovy中有以下代码:- class BootStrap { def dataLoaders; def init = { servletContext -> startLoaders(); } def startLoaders() { for (IDataLoader loader : dataLoaders) { runAsync {

我在Bootstrap.groovy中有以下代码:-

class BootStrap {

    def dataLoaders;

    def init = { servletContext ->
        startLoaders();
    }


    def startLoaders() {
        for (IDataLoader loader : dataLoaders) {
            runAsync {
                loader.setup();
                loader.startLoading();
            }
        }
    }
}
运行应用程序时,会引发以下异常:

ERROR org.codehaus.groovy.grails.web.context.GrailsContextLoader Error initializing the application: No signature of method: BootStrap.runAsync() is applicable for argument types: (BootStrap$_startLoaders_closure3) values: [BootStrap$_startLoaders_closure3@6892f97b]
groovy.lang.MissingMethodException: No signature of method: BootStrap.runAsync() is applicable for argument types: (BootStrap$_startLoaders_closure3) values: [BootStrap$_startLoaders_closure3@6892f97b]
    at BootStrap.startLoaders(BootStrap.groovy:27)
    at BootStrap$_closure1.doCall(BootStrap.groovy:15)
我已经在BuildConfig.groovy的插件部分添加了以下内容:

compile ":executor:0.3"
请尝试以下方法:

class BootStrap {

    def dataLoaders
    def executorService

    def init = { servletContext ->
        startLoaders()
    }

    def startLoaders() {
        for (IDataLoader loader : dataLoaders) {
            executorService.submit({
                loader.setup()
                loader.startLoading()
            } as Callable)
        }
    }
}

ie的可能副本:创建一个服务来完成工作并包含您的数据加载器,将服务注入引导程序,并在init方法中从引导程序调用服务方法。谢谢Tim,这是一个好主意。谢谢Don-grails中提供的选项数量之多让人惊讶。