Archive for the 'java' Category
Using services from bootstrap.groovy in grails
I’m currently writing an application for some upcoming strutta.com functionality using grails. During development though, I have it setup to recreate my data everytime I restart the server, and then I repopulate from a seperate source.
I do have a controller setup to manually import specific ids from the head end server, but its useful if I didn’t have to do this everything I hit ctrl-c in the wrong window. Using a services orientated design, you seperate out logic from controllers (and is recommended by the grails guys), but if you need to call this from the bootup, you could follow the instructions on http://grails.org/Services (which doesn’t work…) or you could do:
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
class BootStrap {
def init = { servletContext ->
def ctx = servletContext.getAttribute(
GrailsApplicationAttributes.APPLICATION_CONTEXT);
def ss = ctx.getBean("feedService");
ss.loadFromFeed();
}
def destroy = {
}
}
2 comments