如何为具有多个数据源的 grails 2.X 应用程序配置 c3p0? [英] How do I configure c3p0 for a grails 2.X application with multiple datasources?

查看:28
本文介绍了如何为具有多个数据源的 grails 2.X 应用程序配置 c3p0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个易于遵循的解决方案(可能是这个问题的答案),用于在具有多个数据源的 grails 2.X Web 应用程序上配置 c3p0 连接池.我无法通过谷歌搜索找到任何明确且简单的帮助.

I'm trying to find an easy-to-follow solution (possibly an answer to this question) for configuring c3p0 connection pooling on a grails 2.X web app with multiple datasources. I have not been able to find any clear and easy help via google searching.

我正在寻找的答案如下:

The answer I'm looking for will say the following:

1) 需要什么罐子

2) 需要修改哪些grails文件

2) What grails files need to be modified

3) 将内容放入这些 grails 文件的示例,包括导入语句和示例代码.

3) Examples of what to put in these grails files including import statements and example code.

假设我的应用中有两个数据源,dataSource 和 dataSource_A 在 DataSource.groovy 中配置.

Assume I have two datasources in my app, dataSource and dataSource_A configured in DataSource.groovy.

如何为 grails 2.X Web 应用程序中的多个数据源配置 c3p0 连接池?

推荐答案

datasource.groovy/外部配置文件

   dataSource {
    pooled = true
    dbCreate = "create-drop"
    url = "jdbc:mysql://<ip address>/test1"
    driverClassName = "com.mysql.jdbc.Driver"
    username = "test"
    password = "test123" 
   }

   dataSource_A {
      pooled = true
      dbCreate = "create-drop"
      url = "jdbc:mysql://<ip address>/test2"
      driverClassName = "com.mysql.jdbc.Driver"
      username = "test"
      password = "test123" 
  }

resources.groovy

 dataSource(ComboPooledDataSource) { bean ->
    idleConnectionTestPeriod = 1 * 60 * 60
    testConnectionOnCheckin = true
    bean.destroyMethod = 'close'
    user = grailsApplication.config.dataSource.username
    password = grailsApplication.config.dataSource.password
    driverClass = grailsApplication.config.dataSource.driverClassName
    jdbcUrl = grailsApplication.config.dataSource.url
}


dataSource_A(ComboPooledDataSource) { bean ->

    idleConnectionTestPeriod = 1 * 60 * 60
    testConnectionOnCheckin = true
    bean.destroyMethod = 'close'
    user = grailsApplication.config.dataSource_A.username
    password = grailsApplication.config.dataSource_A.password
    driverClass = grailsApplication.config.dataSource_A.driverClassName
    jdbcUrl = grailsApplication.config.dataSource_A.url

}

c3p0.jar 位于项目的 lib 文件夹中.

c3p0.jar in the project's lib folder.

这些是唯一需要的更改.

These are the only changes that are required.

这篇关于如何为具有多个数据源的 grails 2.X 应用程序配置 c3p0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆