3
在我的Grails插件我定義以下的Spring beansGrails中的Spring bean定義
def doWithSpring = {
// define a bean of type ConfigObjectHelper
configHelper(ConfigObjectHelper)
// Call a method of the bean we've just defined
String appName = configHelper.getAsString('ftp.general.appName')
// define another bean and pass appName to it's constructor
pkApplication(Application, appName)
}
當我打電話configHelper.getAsString
我得到一個NullPointerException,因爲configHelper
並不是指我在前面行創建的豆。相反,Grails使用這個名字查找當前類的屬性/字段。如果不存在,我會得到一個NullPointerException。
有沒有辦法在doWithSpring
閉包中獲得對Spring bean的引用?
感謝
在doWithApplicationContext關閉中執行pkApplication.appName = configHelper.getAsString(...)是不可能的嗎?在那個階段,所有在doWithSpring中定義的bean都被實例化。 – 2011-02-18 09:39:43