![](/img/trans.png)
[英]Dynamic domain methods missing from grails service when injected into java service in grails app
[英]Service is not getting injected into Grails domain class , Grails 2.0.0 and 2.0.3
我尝试了多次重启app,并从2.0.0升级到2.0.3,没有任何帮助。 我总是得到这样的信息:
: def getCustomerName(){64: customerService.name
"Cannot get property 'name' on null object"
相关域类部分:
class Instance {
def customerService
...
def getCustomerName(){
customerService.name
}
相关服务类:
class CustomerService {
我正在尝试从可以访问Instance对象的视图中访问getCustomerName方法。 也尝试了另一项服务,同样的结果。
这里只是一个猜测 - 以下读取类似于getter方法:
def getCustomerName()
在依赖注入发生之前,框架是否有可能检查getter和setter方法的有效性?
几年前,Burt回答了一个关于在onLoad()中使用依赖注入的问题,看起来就是这样。 他建议:
添加此导入:
import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
然后将客户服务引用为
def customerService = AH.application.mainContext.customerService
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.