【发布时间】:2011-06-29 02:58:01
【问题描述】:
在我的 Grails 插件中,我定义了以下 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 没有引用我在上一行中创建的 bean。相反,Grails 会使用该名称查找当前类的属性/字段。由于不存在,我得到一个 NullPointerException。
有没有办法在 doWithSpring 闭包中获取对 Spring bean 的引用?
谢谢
【问题讨论】:
-
难道不能在 doWithApplicationContext 闭包中执行 pkApplication.appName = configHelper.getAsString(...) 吗?在那个阶段,doWithSpring 中定义的所有 bean 都被实例化了。
标签: spring grails groovy grails-plugin