Comment puis-je amorcer complètement un environnement de Grails?
-
06-09-2019 - |
Question
Je le script inclus Grails que j'ai trouvé dans un endroit au hasard sur Internet et il fonctionne assez bien pour la cuisson des scripts dans un env de Grails bootstrapped. La seule chose qu'il ne semble pas faire est le coup d'envoi de mes scripts conf/*Bootstrap.groovy
comme quand je fais app courir.
Y at-il une autre fonction comme loadApp()
et configureApp()
qui le fera pour moi?
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()
}
}
La solution
Oui, essayez
new (Bootstrap). Init ()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow