`
huangcanqin
  • 浏览: 28247 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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);
                    }
                }

 

分享到:
评论
Global site tag (gtag.js) - Google Analytics