对于使用Grails 3的creating multiple datasources来说,文档非常简单,但是我无法让它工作。
当我配置第二个数据源时,即使我不在代码中的任何地方使用它,我也会收到以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
这让我相信我的application.yml文件中有错误。这是相关的代码:
dataSources:
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: "org.hibernate.dialect.MySQL5InnoDBDialect"
lookup:
driverClassName: com.mysql.jdbc.Driver
dialect: "org.hibernate.dialect.MySQL5InnoDBDialect"
environments:
development:
dataSources:
dataSource:
dbCreate: create-drop
url: jdbc:mysql://localhost/maindb?useUnicode=yes&characterEncoding=UTF-8
username: "root"
password: "fakepwd"
lookup:
dbCreate: create-drop
url: jdbc:mysql://localhost/docreds?useUnicode=yes&characterEncoding=UTF-8
username: "root"
password: "fakepwd"
test:
dataSources:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=9000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSources:
dataSource:
dbCreate: update
url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=8000;DB_CLOSE_ON_EXIT=FALSE
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
删除 dataSources 以及相关定义会使应用程序进入工作状态