配置Grails以使用自己的DataSource实现或代理标准DataSource

编程入门 行业动态 更新时间:2024-10-14 12:21:33
本文介绍了配置Grails以使用自己的DataSource实现或代理标准DataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在应用程序中,我想使用自己的 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

本文发布于:2023-10-26 18:29:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自己的   标准   Grails   DataSource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!