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

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

问题描述

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



我正在寻找的答案将如下所示:



1)需要什么罐子



2)需要修改哪些grails文件



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



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

解决方案

datasource.groovy /外部配置文件
$ b

  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

}
code>

c3p0.jar 在项目的lib文件夹中。



这些是必需的唯一更改。


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) What jars are needed

2) What grails files need to be modified

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

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

How do I configure c3p0 connection pooling for multiple datasources in a grails 2.X web app?

解决方案

datasource.groovy / External configuration file

   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 in the project's lib folder.

These are the only changes that are required.

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

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