[英]Service is not getting injected into Grails domain class , Grails 2.0.0 and 2.0.3
I've tried multiple app restarts, and upgrading from 2.0.0 to 2.0.3, no help. 我尝试了多次重启app,并从2.0.0升级到2.0.3,没有任何帮助。 I always get this message: 我总是得到这样的信息:
: def getCustomerName(){64: customerService.name
"Cannot get property 'name' on null object"
Relevant domain class part: 相关域类部分:
class Instance {
def customerService
...
def getCustomerName(){
customerService.name
}
Relevant Service class: 相关服务类:
class CustomerService {
I'm trying to access the getCustomerName method from a view which has access to an object of Instance. 我正在尝试从可以访问Instance对象的视图中访问getCustomerName方法。 Also tried this with another service, same result. 也尝试了另一项服务,同样的结果。
Just a guess here - the following reads like a getter method: 这里只是一个猜测 - 以下读取类似于getter方法:
def getCustomerName()
Is it possible that the framework is checking the getter and setter methods for validity before the dependency injection takes place? 在依赖注入发生之前,框架是否有可能检查getter和setter方法的有效性?
Burt answered a question a couple of years ago regarding using dependency injection in an onLoad() and it appeared that is what was happening. 几年前,Burt回答了一个关于在onLoad()中使用依赖注入的问题,看起来就是这样。 He advised: 他建议:
Add this import: 添加此导入:
import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
and then reference the customer service as 然后将客户服务引用为
def customerService = AH.application.mainContext.customerService
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.