Grails domain class initialization
-
25-09-2019 - |
Question
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("foo@doo.com")
}
}
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
No correct solution
OTHER TIPS
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()
}
}
The following works without any config in resources.groovy
class CalendarService {
@PostConstruct
private void init() {
User.findByEmail("foo@doo.com")
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow