我的 Grails 应用程序在 spring/resources.groovy
中定义了以下 Spring bean
calendarService(CalendarService) { bean ->
bean.initMethod = "init"
}
这个方法看起来像:
class CalendarService {
void init() {
User.findByEmail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99fff6f6d9fdf6f6b7faf6f4" rel="noreferrer noopener nofollow">[email protected]</a>")
}
}
当我调用动态查找器findByEmail
时,我得到一个MissingMethodException
。我的猜测是,我试图过早地调用此方法,即在域类将动态查找器添加到其元类之前。一种解决方案是自己从 Bootstrap.init 调用 CalendarService.init(),而不是指示 Spring 调用它,但是有更好的解决方案吗?
谢谢, 唐
最佳答案
你是对的,正如post中所述。 ,如果你需要动态方法,你最好使用 BootStrap.groovy
BootStrap {
def calendarService
def init() {
calendarService.init()
}
}
关于spring - Grails 域类初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2809712/