views:

160

answers:

1

Hi,

My Grails app has the following Spring bean defined in spring/resources.groovy

calendarService(CalendarService) { bean ->
    bean.initMethod = "init"     
}

This method looks something like:

class CalendarService {
    void init() {
        User.findByEmail("[email protected]")
    }   
}

When I call the dynamic finder findByEmail I get a MissingMethodException. My guess is that I'm trying to call this method too early, i.e. before the domain classes have had the dynamic finders added to their metaclass. One solution would be to call CalendarService.init() myself from Bootstrap.init, rather than instructing Spring to call it, but is there a better solution?

Thanks, Don

+2  A: 

You're right, as described in this post, if you need the dynamic methods you'd better go with BootStrap.groovy

BootStrap {
    def calendarService
    def init() {
        calendarService.init()
    }
}
Felipe Cypriano