关于hibernate.proxool.existing_pool

来源:互联网 发布:软件开发流程管理 编辑:程序博客网 时间:2024/06/05 16:27

在Web项目中有时会使用hibernate和jdbc两种方式访问数据库,还有一种情况是使用spring管理hibernate时,同时采用自动和手动两种方式加载applicationContext.xml,如果不设置hibernate.proxool.existing_pool会抛出异常,因为proxool在hibernate开始调用时已经初始化了,解决这个问题可以将proxool手动初始化。以下是解决步骤:

1.首先自己实现ServletContextListener,由于如果spring采用filter方式在初始化时需要获得连接,必须在spring初始化前首先初始化proxool。

ServletContextListener:

 

web.xml:

 

2.设置hibernate配置hibernate.proxool.existing_pool为true,使用已经存在的proxool连接池。

hibernate.cfg.xml