相关推荐:Proxool在web项目中的配置,以及与spring3、hibernate4的集成

一、 Proxool 简介 一种java数据库连接池技术。是sourceforge下的一个开源项目,这个项目提供了一个健壮已用的连接池,同时提供了这个连接池的监控功能。 目前最为常见的三种JDBC连接池技术: C3P0 一般运用于开发当中; DBCP Hibernate3.0

Proxool连接池Spring3.1Hibernate3.6鉴于Spring3.0不采用Servlet启动,改用listener,并且针对Mysql与DBCP连接池在linux服务器上超时连接的Bug,现简要地做Spring3与Proxool连接池的配置: 1.Web.xml配置:Java代码

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><!--启动连接池--><servlet><servlet-name>ServletConfigurator</servlet-name><servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class><init-param><param-name>xmlFile</param-name><param-value>WEB-INF/proxool.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!--启动spring(spring3.1)--><context-param><param-name>contextConfigLocation</param-name><param-value>WEB-INF/classes/com/dx/bags/config/applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener></web-app>proxool.xml<位于WEB-INF目录下,与web.xml同目录>[b]本文中由于有多数据库连接,于是,做了多个配置。alias分别为db12,db10,db5[/b]<?xml version="1.0" encoding="UTF-8"?><proxool-config><proxool><alias>db12</alias><driver-url>jdbc:mysql://192.168.1.12:3306/dbname1</driver-url><driver-class>com.mysql.jdbc.Driver</driver-class><driver-properties><property name="user" value="root" /><property name="password" value="*******" /></driver-properties><maximum-new-connections>10</maximum-new-connections><prototype-count>5</prototype-count><test-before-use>true</test-before-use> <test-after-use>true</test-after-use> <house-keeping-sleep-time>60000</house-keeping-sleep-time> <house-keeping-test-sql>select current_date from dual</house-keeping-test-sql><maximum-connection-count>10</maximum-connection-count><minimum-connection-count>2</minimum-connection-count></proxool><proxool><alias>db10</alias><driver-url>jdbc:mysql://192.168.1.10:3306/dbname2</driver-url><driver-class>com.mysql.jdbc.Driver</driver-class><driver-properties><property name="user" value="root" /><property name="password" value="******" /></driver-properties><maximum-new-connections>10</maximum-new-connections><prototype-count>5</prototype-count><test-before-use>true</test-before-use> <test-after-use>true</test-after-use> <house-keeping-sleep-time>60000</house-keeping-sleep-time> <house-keeping-test-sql>select current_date from dual</house-keeping-test-sql><maximum-connection-count>10</maximum-connection-count><minimum-connection-count>2</minimum-connection-count></proxool><proxool><alias>db5</alias><driver-url>jdbc:mysql://192.168.1.5:3306/dbname3</driver-url><driver-class>com.mysql.jdbc.Driver</driver-class><driver-properties><property name="user" value="***" /><property name="password" value="****" /></driver-properties><maximum-new-connections>10</maximum-new-connections><prototype-count>5</prototype-count><test-before-use>true</test-before-use> <test-after-use>true</test-after-use> <house-keeping-sleep-time>60000</house-keeping-sleep-time> <house-keeping-test-sql>select current_date from dual</house-keeping-test-sql><maximum-connection-count>10</maximum-connection-count><minimum-connection-count>2</minimum-connection-count></proxool></proxool-config>Hibernate.cfg.xml配置:文件位于src目录下。<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. --><hibernate-configuration><session-factory><property name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="myeclipse.connection.profile">mysql</property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.proxool.existing_pool">true</property><property name="hibernate.proxool.xml">proxool.xml</property><property name="hibernate.proxool.pool_alias">db12</property><property name="hibernate.proxool.pool_alias">db10</property><property name="hibernate.proxool.pool_alias">db5</property></session-factory></hibernate-configuration>Spring 配置文件中对于datasource和sessionFactory配置片断:<bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName"><value>org.logicalcobwebs.proxool.ProxoolDriver</value></property><property name="url"><value>proxool.db12</value></property></bean><bean id="latestDataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName"><value>org.logicalcobwebs.proxool.ProxoolDriver</value></property><property name="url"><value>proxool.db5</value></property></bean><bean id="adminDataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName"><value>org.logicalcobwebs.proxool.ProxoolDriver</value></property><property name="url"><value>proxool.db10</value></property></bean><bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="mappingDirectoryLocations"><list><value>classpath:com/dx/bags/hibernate/hbm</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.proxool.pool_alias">db12</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.proxool.xml">proxool.xml</prop><prop key="hibernate.proxool.existing_pool">true</prop></props></property></bean><bean id="latestdbSessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource" ref="latestDataSource"></property><property name="mappingDirectoryLocations"><list><value>classpath:com/dx/bags/hibernate/hbm/latest</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.proxool.pool_alias">db5</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.proxool.xml">proxool.xml</prop><prop key="hibernate.proxool.existing_pool">true</prop></props></property></bean><bean id="adminSessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource" ref="adminDataSource"></property><property name="mappingDirectoryLocations"><list><value>classpath:com/dx/bags/hibernate/hbm/admin</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.proxool.pool_alias">db10</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.proxool.xml">proxool.xml</prop><prop key="hibernate.proxool.existing_pool">true</prop></props></property>

</bean>关于proxool配置文件中的各参数就不多做说明了。很简单易懂。连接池所要JAR:proxool-0.9.1.jar,proxool-cglib.jar。

相关推荐:SSH框架下 Proxool 连接池配置

第一步.添加jar包:proxool-0.9.1.jar,proxool-cglib.jar 在WEB-INF下,创建proxool.xml文件,代码如下: <xml version="1.0" encoding="UTF-8"><proxool><alias>sqlserver2000</alias><driver-url>jdbc:sqlserver://192.168.1.123:1433;databaseName=Te

快照源:http://my.oschina.net/dyyweb/blog/32810