【发布时间】:2011-01-31 22:29:51
【问题描述】:
我希望 grails 服务能够访问域静态方法、查询等。
例如,在控制器中,我可以调用
IncomingCall.count()
获取“IncomingCall”表中的记录数
但如果我尝试从服务内部执行此操作,则会收到错误消息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingStatusService': Invocation of init method failed; nested exception is groovy.lang.MissingMethodException: No signature of method: static ms.wdw.tropocontrol.IncomingCall.count() is applicable for argument types: () values: []
这些方法是如何被注入的?在控制器中似乎没有神奇的 def 语句可以做到这一点。还是我的 Service 类中没有 Hibernate 的问题?
我也试过这样:
import ms.wdw.tropocontrol.IncomingCall
import org.codehaus.groovy.grails.commons.ApplicationHolder
// ...
void afterPropertiesSet() {
def count = ApplicationHolder.application.getClassForName("IncomingCall").count()
print "Count is " + count
}
它失败了。 ApplicationHolder.application.getClassForName("IncomingCall") 返回 null。这么称呼是不是太早了?有没有可以调用的“后期初始化”?我以为这就是“afterPropertiesSet()”的目的……
【问题讨论】:
-
您是否尝试将包含 IncomingCall 域的包包含到您的服务源中?
-
是的。我有一个导入声明。
标签: hibernate grails groovy dns