在我的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的引用?
谢谢
解决方法:
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)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。