grails - 如何完全引导Grails环境?

标签 grails bootstrapping

我有包含的grails脚本,可以在Internet上的某个随机位置找到它,它对于在自举的grails env中启动脚本非常有效。似乎唯一没有做的就是像运行应用程序一样启动conf/*Bootstrap.groovy脚本。

还有像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()
    }
}

最佳答案

是的,尝试

new BootStrap().init()

关于grails - 如何完全引导Grails环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/930227/

相关文章:

compiler-construction - 引导仍然需要外部支持

hibernate - Grails:无法设置参数的值,并且获取时不能为null

grails - Grails 'Cannot issue a redirect'问题

javascript - (Groovy/Grails) 如何处理 JavaScript 模块中需要根据环境更改的 URL (dev/prod/qa/etc)

php - 引导 View

grails - 如何在 Bootstrap 中获取 grails 数据源 createdb 属性

php - Composer 包测试 Bootstrap

gcc - 为什么 GCC 会自己编译 3 次?

找不到名称的 Grails 3.2.0.M1 模板

mysql - 使用grails run-app获取 'java.sql.SQLException: com.mysql.jdbc.Driver'(当BuildConfig.groovy不需要重新编译时)