在 Grails 2.3.6 中定义备用连接池 [英] Defining an alternate connection pool in Grails 2.3.6
问题描述
我知道,在 Grails 1.X 和 Grails 2.X 之间的某个时间点,默认连接池库从 commons-dbcp
更改为 tomcat-dbcp
.
I know that, at some point between Grails 1.X and Grails 2.X, the default connection pooling library changed from commons-dbcp
to tomcat-dbcp
.
现在,我正在尝试将 BoneCP 或 HikariCP 配置为我的 Grails 应用程序的连接池库.
Now, I'm trying to configure either BoneCP or HikariCP as the connection pooling library for my Grails application.
但是,我看到 这个答案提供了一个可能仅适用于 Grails 1.X 的解决方案.
However, I see that this answer offers a solution which might only apply to Grails 1.X.
我也找到了这个要点,但同样,我不知道是哪个 Grails 版本它适用于.
I also found this Gist, but again, I don't know which Grails version it applies to.
那么,是否可以在 Grails 2.3.6 应用程序中定义自定义连接池?谢谢!
So, is it possible to define a custom connection pool inside a Grails 2.3.6 application? Thanks!
推荐答案
UPDATE: 好的,所以您实际上需要告诉 Grails 不要 池化数据源,因为 HikariCP 是现在正在处理这个.
UPDATE: OK so you actually need to tell Grails not to pool the datasources, since HikariCP is now taking care of this.
如果我打开那个开关,我会在我的应用程序中看到连接异常.所以改为说:
I saw connection weirdness in my apps if I left that switch on. So instead say:
pooled = false
好吧,@Joshua Moore 是对的.
OK yeah, @Joshua Moore is right.
我尝试使用更新的 Grails 方法来做这件事,这是我的 resources.groovy
文件的相关部分.据我了解,Datasource.groovy
中的配置值在运行时被拉入 resources.groovy
、test
或 production
).
I tried doing it with updated Grails methods and this is the relevant section of my resources.groovy
file. As far as I can understand, the configuration values in Datasource.groovy
are pulled into resources.groovy
at runtime, after the target runtime environment has been identified (development
, test
or production
).
def config = Holders.config
def dataSources = config.findAll {
it.key.toString().contains("dataSource_")
}
dataSources.each { key, value ->
def ds = value
"${key}"(HikariDataSource, { bean ->
def hp = new Properties()
hp.username = ds.username
hp.password = ds.password
hp.connectionTimeout = 6000
hp.maximumPoolSize = 60
hp.jdbcUrl = ds.url
hp.driverClassName = ds.driverClassName
HikariConfig hc = new HikariConfig(hp)
bean.constructorArgs = [hc]
})
}
这是我的 DataSource.groovy
配置的相关部分:
And this is the relevant section of my DataSource.groovy
configuration:
// environment specific settings
environments {
development {
dataSource_myapp1 {
pooled = false
username = "CONFIGURE_ME_EXTERNALLY"
password = "CONFIGURE_ME_EXTERNALLY"
driverClassName = 'oracle.jdbc.OracleDriver'
dialect = 'org.hibernate.dialect.Oracle10gDialect'
url = 'jdbc:oracle:thin:@MYDBHOST1:1521/MYSERVICEID1'
}
dataSource_myApp2 {
pooled = false
username = "CONFIGURE_ME_EXTERNALLY"
password = "CONFIGURE_ME_EXTERNALLY"
driverClassName = 'oracle.jdbc.OracleDriver'
dialect = 'org.hibernate.dialect.Oracle10gDialect'
url = 'jdbc:oracle:thin:@MYDBHOST2:1521/MYSERVICEID2'
}
}
}
就我而言,test
和 production
环境几乎相同.谢谢!
In my case, it's pretty much the same for test
and production
environments. Thanks!
这篇关于在 Grails 2.3.6 中定义备用连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!