在应用程序中,我想使用自己的 javax.sql.DataSource 实现扩展标准 org.apachemons.dbcp。 Grails使用的BasicDataSource ,并添加了基于Grails应用程序中当前登录用户设置客户端标识符的功能。
In an application I want to use my own implementation of javax.sql.DataSource that extends the standard org.apachemons.dbcp.BasicDataSource used by Grails and adds the functionality to set the client identifier based on the currently logged in user at the Grails application.
在Grails应用程序中更改底层 javax.sql.DataSource 实现的最佳方式?
What is the best way to change the underlying javax.sql.DataSource implementation in a Grails application?
两种可能性:
- 更改Grails使用的DataSource的实现
- 代理DataSource由Grails使用并添加AOP的功能
有关如何处理此要求的任何提示?
Any hints on how to deal with this requirement?
推荐答案这里是我的 resources.groovy
import org.codehaus.groovy.grailsmons.ConfigurationHolder as CH // Place your Spring DSL code here beans = { /** * c3P0 pooled data source that forces renewal of DB connections of certain age * to prevent stale/closed DB connections and evicts excess idle connections * Still using the JDBC configuration settings from DataSource.groovy * to have easy environment specific setup available */ dataSource(com.mchange.v2.c3p0.ComboPooledDataSource) { bean -> bean.destroyMethod = 'close' //use grails' datasource configuration for connection user, password, driver and JDBC url user = CH.config.dataSource.username password = CH.config.dataSource.password driverClass = CH.config.dataSource.driverClassName jdbcUrl = CH.config.dataSource.url //force connections to renew after 2 hours maxConnectionAge = 2 * 60 * 60 //get rid too many of idle connections after 30 minutes maxIdleTimeExcessConnections = 30 * 60 } }我使用 c3p0 ComboPooledDataSource
i'm using c3p0 ComboPooledDataSource
更多推荐
配置Grails以使用自己的DataSource实现或代理标准DataSource
发布评论