Search code examples
grailscontrollers

Execute controller method on startup (Grails)


I have an event controller with a populate() method which adds events from a JSON link to my database. I want this to occur on startup of my server.

I've tried various things in my Bootstrap file. Such as:

def event = new EventController.populate()

Solution

  • You really should move that code into a service and out of your controller. This gives you a lot more options, including injecting the service into your Bootstrap.groovy and calling the method on startup of the application.

    That's a much more proper Grails solution.