0

Is there a way to get a list of available dataSources in grails (or using hibernate methods)?

Let's say I have this in my config:

dataSource {
    dbCreate = "update"
    url = "jdbc:h2:mem:testDb;MVCC=TRUE"
}

dataSource_ALT {
   dbCreate = "update"
   url = "jdbc:h2:mem:altDb;MVCC=TRUE"
}

How can I know at runtime I have these data sources (and possibly switch them)?

I am using grails 2.4.3 specifically.

5
  • Does this help? guides.grails.org/grails-dynamic-multiple-datasources/guide/… inject @Autowired HibernateDatastore hibernateDatastore and access hibernateDatastore.connectionSources.getProperties().get("allConnectionSources") Oct 7, 2019 at 19:27
  • I've also used grailsApplication.config.getProperty("dataSources.alt.url", String) to get access to current datasource configs. Oct 7, 2019 at 19:29
  • @JasonHeithoff I get this error ERROR: No such property: connectionSources for class: org.codehaus.groovy.grails.orm.hibernate.HibernateDatastore
    – Behlül
    Oct 8, 2019 at 0:07
  • Try this import instead: org.codehaus.groovy.grails.orm.hibernate.HibernateDatastore Oct 8, 2019 at 0:26
  • @JasonHeithoff That is the exact same class in my error.
    – Behlül
    Oct 8, 2019 at 15:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.