Configuring Grails to use own DataSource implementation or to proxy the standard DataSource

后端 未结 2 2107
挽巷
挽巷 2020-12-19 11:54

In an application I want to use my own implementation of javax.sql.DataSource that extends the standard org.apache.commons.dbcp.BasicDataSource use

相关标签:
2条回答
  • 2020-12-19 12:30

    did you try configuring your own datasource in resources.groovy? Here is a blog post (not mine) that goes over the process

    http://burtbeckwith.com/blog/?p=312

    the stuff you need is at the end.

    0 讨论(0)
  • 2020-12-19 12:41

    here is my resources.groovy

    import org.codehaus.groovy.grails.commons.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
        }
    
    }
    

    i'm using c3p0 ComboPooledDataSource

    0 讨论(0)
提交回复
热议问题