سؤال

لدي Script شملت الجواب التي وجدت في مكان عشوائي على شبكة الإنترنت ويعمل بشكل جيد للغاية لإطلاق البرامج النصية في قضبان التمهيد. الشيء الوحيد الذي لا يبدو أنه يفعل هو ركلة بلدي 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()
    }
}
هل كانت مفيدة؟

المحلول

نعم، حاول

bootstrap جديد (). INIT ()

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top