Can I list all of the dataSources available?

丶灬走出姿态 提交于 2019-12-11 13:11:51

问题


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?


回答1:


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 -

http://plugins.grails.org/grails-datasources/trunk/src/groovy/com/burtbeckwith/grails/plugin/datasources/DatasourcesUtils.groovy



来源:https://stackoverflow.com/questions/9708067/can-i-list-all-of-the-datasources-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!