簡體   English   中英

服務沒有注入Grails域類,Grails 2.0.0和2.0.3

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM