Grails domain class initialization
-
25-09-2019 - |
문제
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
올바른 솔루션이 없습니다
다른 팁
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")
}
}
제휴하지 않습니다 StackOverflow