在我的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的引用?
谢谢
发布于 2011-02-18 19:40:54
MethodInvokingFactoryBean出手相救!
def doWithSpring = {
// define a bean of type ConfigObjectHelper
configHelper(ConfigObjectHelper)
appName(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
targetObject = ref('configHelper')
targetMethod = 'getAsString'
arguments = ['ftp.general.appName']
}
// define another bean and pass appName to it's constructor
pkApplication(Application, appName)
}https://stackoverflow.com/questions/5029779
复制相似问题