Grails 域类初始化
我的 Grails 应用程序在 spring/resources.groovy
中定义了以下 Spring bean
calendarService(CalendarService) { bean ->
bean.initMethod = "init"
}
该方法看起来类似于:
class CalendarService {
void init() {
User.findByEmail("[email protected]")
}
}
当我调用动态查找器 findByEmail
时,我得到一个 MissingMethodException< /代码>。我的猜测是,我试图过早地调用此方法,即在域类将动态查找器添加到其元类之前。一种解决方案是自己从 Bootstrap.init 调用 CalendarService.init(),而不是指示 Spring 调用它,但是有更好的解决方案吗?
谢谢, 大学教师
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要动态方法,您是对的,正如这篇帖子中所述你最好使用 BootStrap.groovy
You're right, as described in this post, if you need the dynamic methods you'd better go with BootStrap.groovy
以下内容无需在
resources.groovy
中进行任何配置即可工作The following works without any config in
resources.groovy