Using a Grails service inside a script -


i'm trying use grails service inside following grails script

includetargets << grailsscript("_grailsinit")  target(loadgames: "the description of script goes here!") {    def listfile = new file('list.txt')     listfile.eachline {       def result = ctx.getbean("bggservice").search(it)       println + " " + result.length()    } }  setdefaulttarget(loadgames) 

i've seen dozen different webpages each offering different combination of ctx appctx, , applicationcontext (as many others) suggestions, none of them work. typically complain context variable trying use not exist.

why can't grails use services inside script in same way used in controllers?

what right way use grails service inside grails script?

getting hold of applicationcontext , grailsapplication possible though bootstrap command. include _grailsbootstrap script, call configureapp () or depend on in order make applicationcontext available in script:

includetargets << grailsscript("_grailsinit") includetargets << grailsscript("_grailsbootstrap")  target(loadgames: "the description of script goes here!") {    depends(configureapp)     def listfile = new file('list.txt')     listfile.eachline {       //once configureapp() called applicationcontext can accessed appctx       def result = appctx.getbean("bggservice").search(it)       println + " " + result.length()    } }  setdefaulttarget(loadgames) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -