当我尝试将值分配给变量“newDBName”时,出现错误:
ERROR [grails.app.controllers] groovy.lang.MissingMethodException:
No signature of method: DataSourceConfigService.$() is applicable for
argument types: DataSourceConfigService$_injectNewDatasource_closure1_closure3)
values: [DataSourceConfigService$_injectNewDatasource_closure1_closure3@1e1ae104]
码:
class DataSourceConfigService {
def injectNewDatasource() {
String newDBName = ""
Environment.list().each {env ->
if( !grailsApplication.mainContext.containsBean( "${env.accountName}" ) ) {
def bb = new BeanBuilder()
bb.beans {
"${env.accountName}"(ComboPooledDataSource) {bean -> ...}
bb.registerBeans( grailsApplication.mainContext );
}
log.info "Added bean called ${env.accountName}"
newDBName = ${env.accountName}
}
}
return newDBName
}
}
这是我调用该函数的方式:
String newDBName = dataSourceConfigService.injectNewDatasource()
最佳答案
您在newDBName
分配行上缺少引号。无论使用
newDBName = "${env.accountName}"
或只是跳过到GString的转换(至少根据此代码段看起来是不必要的),然后使用
newDBName = env.accountName
关于grails - Grails框架:groovy.lang.MissingMethodException:方法无签名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54894715/