Here's a current postgres example with multiple datasources. I found that the redundancy was necessary because there were some discrepancies in the levels that grails, spring and hibernate were expecting to see config information. this satisfied all of them. also include a runtime dependency for your jdbc driver. for postgres, it was
dependencies {
// all other dependencies
runtime "org.postgresql:postgresql:9.4.1208"
}
[Start of application.yml file. yes, the '---' lines need to be there. they keep the configslurper from getting confused.]
---
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.H2Dialect
dataSources:
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.H2Dialect
dataSource:
pooled: true
jmxExport: true
driverClassName: org.postgresql.Driver
driver_class: org.postgresql.Driver
username: user
password: pw
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbone
connection.username: user
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbone
username: user
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
dataSource_two:
pooled: true
jmxExport: true
driverClassName: org.postgresql.Driver
driver_class: org.postgresql.Driver
username: usertwo
password: pw
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbtwo
connection.username: usertwo
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbtwo
username: usertwo
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
dataSource_three:
pooled: true
jmxExport: true
driverClassName: org.postgresql.Driver
driver_class: org.postgresql.Driver
username: userthree
password: pw
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbthree
connection.username: userthree
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbthree
username: userthree
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
environments:
local:
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.H2Dialect
dataSources:
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.H2Dialect
dataSource:
dbCreate: create
url: jdbc:postgresql://127.0.0.1:5432/dbone
driver_class: org.postgresql.Driver
driverClassName: org.postgresql.Driver
username: userone
password: pw
pool_size: 15
dialect: org.hibernate.dialect.PostgreSQLDialect
logSql: true
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://127.0.0.1:5432/dbone
connection.username: userone
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://127.0.0.1:5432/dbone
username: userone
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
dataSource_two:
dbCreate: create
url: jdbc:postgresql://127.0.0.1:5432/dbtwo
driver_class: org.postgresql.Driver
driverClassName: org.postgresql.Driver
username: usertwo
password: pw
pool_size: 15
dialect: org.hibernate.dialect.PostgreSQLDialect
logSql: true
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://127.0.0.1:5432/dbtwo
connection.username: usertwo
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://127.0.0.1:5432/dbtwo
username: usertwo
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
dataSource_three:
dbCreate: create
url: jdbc:postgresql://127.0.0.1:5432/dbthree
driver_class: org.postgresql.Driver
driverClassName: org.postgresql.Driver
username: userthree
password: pw
pool_size: 15
dialect: org.hibernate.dialect.PostgreSQLDialect
logSql: true
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://127.0.0.1:5432/dbthree
connection.username: userthree
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://127.0.0.1:5432/dbthree
username: userthree
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
development:
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.H2Dialect
dataSources:
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.H2Dialect
dataSource:
dbCreate: create-drop
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbone
driver_class: org.postgresql.Driver
driverClassName: org.postgresql.Driver
username: userone
password: pw
pool_size: 15
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbone
connection.username: userone
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbone
username: userone
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
dataSource_two:
dbCreate: create-drop
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbtwo
driver_class: org.postgresql.Driver
driverClassName: org.postgresql.Driver
username: usertwo
password: pw
pool_size: 15
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbtwo
connection.username: usertwo
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbtwo
username: usertwo
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
dataSource_three:
dbCreate: create-drop
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbthree
driver_class: org.postgresql.Driver
driverClassName: org.postgresql.Driver
username: userthree
password: pw
pool_size: 15
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dialect: org.hibernate.dialect.PostgreSQLDialect
connection.driver_class: org.postgresql.Driver
connection.url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbthree
connection.username: userthree
connection.password: pw
connection.pool_size: 15
connection.dialect: org.hibernate.dialect.PostgreSQLDialect
driver_class: org.postgresql.Driver
url: jdbc:postgresql://ec2-1-2-3-4.compute-1.amazonaws.com:5432/dbthree
username: userthree
password: pw
pool_size: 15
driverClassName: org.postgresql.Driver
---
---
[ this is not the end of the application.yml, just the end of the datasource section.]