bonecp 与 osgi 整合

bonecp 号称是opensource 中性能最好的数据库连接池。但对osgi application 支持却不是很好。个人在整合bonecp与osgi 时出现数据库driver not found ,于是查看源码发现在BoneCP中采用DriverManager.getConnection获取连接,由于osgi 特性导致classLoader 没权限加载driver。

个人对源码进行部分修改,目前能够在virgo 下运行。

源码修改:在obtainRawInternalConnection方法中增加代码

if(this.config.getDriver()!=null){
                    try {
                        Driver driver=(Driver)this.config.getDriver().newInstance();
                        if(props==null){
                            props = new Properties();
                            props.put("user", username);
                            props.put("password", password);
                        }
                        result=driver.connect(url, props);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                    }
                }else{
                    if (props != null){
                        result = DriverManager.getConnection(url, props);
                    } else {
                        result = DriverManager.getConnection(url, username, password);
                    }
                }

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值