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