我如何完全引导grails环境?

时间:2009-05-30 18:03:31

标签: grails bootstrapping

我在互联网上的一些随机位置找到了包含的grails脚本,它非常适合在bootstrapped grails环境中启动脚本。它似乎唯一没有做的就是启动我的conf/*Bootstrap.groovy脚本,就像我运行app一样。

还有其他功能,例如loadApp()configureApp()会为我做这件事吗?

import org.codehaus.groovy.grails.support.PersistenceContextInterceptor

Ant.property(environment: "env")
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"

includeTargets << new File("${grailsHome}/scripts/Bootstrap.groovy")

target('default': "Runs scripts in the test/local directory") {
    if (!args) { throw new RuntimeException("[fail] This script requires an argument - the script to run.") }

    depends(configureProxy, packageApp, classpath)
    classLoader = new URLClassLoader([classesDir.toURI().toURL()] as URL[], rootLoader)
    Thread.currentThread().setContextClassLoader(classLoader)
    loadApp()
    configureApp()

    def interceptor = null
    def beanNames = appCtx.getBeanNamesForType(PersistenceContextInterceptor)
    if (beanNames && beanNames.size() == 1) {
        interceptor = appCtx.getBean(beanNames[0])
    }
    try {
        interceptor?.init()
        new GroovyScriptEngine(Ant.antProject.properties."base.dir", classLoader).run("scripts/${args}.groovy", new Binding(['appCtx':appCtx]))
        interceptor?.flush()
    } catch (Exception e) {
        e.printStackTrace()
        interceptor?.clear()
    } finally {
        interceptor?.destroy()
    }
}

1 个答案:

答案 0 :(得分:1)

是的,试试

  

new BootStrap()。init()