问题描述
我想遍历当前环境的所有可用数据源,试图查看它们中是否包含特定的域实例。每个环境都有不同的数据源。
到目前为止我已经破解的最好的版本是 grailsApplication.config.findAll {it.key.contains(' dataSource_')}
。有没有更好或更合理的方法来做到这一点?
您也可以在应用程序上下文中针对bean名称进行查询。
类似于
ctx.beanDefinitionNames.findAll {it.contains('dataSource')}
>至少这就是Datasources插件中的DatasourcesUtils所做的事情 -
I would like to iterate over all the available dataSources for the current environment, trying to see if any of them contain a particular domain instance. Each environment has different dataSources.
The best I've hacked up so far is grailsApplication.config.findAll { it.key.contains('dataSource_') }
. Is there a better or more legitimate way to do this?
You can also query against the bean names in the application context.
Something like
ctx.beanDefinitionNames.findAll{ it.contains( 'dataSource' ) }
At least that is what the DatasourcesUtils in the Datasources plugin does -
这篇关于我可以列出所有可用的数据源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!