簡體   English   中英

grails spring bean的定義

[英]grails spring bean definition

在我的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的doWithSpring

謝謝

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)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM