Can I list all of the dataSources available?
-
14-12-2019 - |
Question
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?
Solution
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 -
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow