Grails — Running bootstrap with Grails Console

Meni Lubetkin
Meni Lubetkin
Published in
1 min readFeb 14, 2012

you want to test or check your domain model after setting your environment or creating some data on the bootStrap:

How to run the bootstrap from Grails console and set the ApplicationContext and the grailsApplication

from the Grails documentation:

Starts the Grails console, which is an extended version of the regular Groovy console. There are a couple of useful variables registered in the binding:
ctx — The Spring ApplicationContext instance
grailsApplication — The GrailsApplication instance

if you are using the ‘GrailsApplication’ in your bootstrap implement a setter for the grailsApplication
like:


def setGrailsApplication = { grailsApp->
grailsApplication = grailsApp
}

on the console write:


def b = new BootStrap()
b.setGrailsApplication(grailsApplication)
b.init(ctx.servletContext)

now you can write and run your code…

--

--