spring中以dataSource方式使用proxool连接池

spring中以dataSource方式使用proxool连接池 :
转自:http://blog.csdn.net/goodhumor/article/details/2144911
在Spring的"applicationContext.xml"中的dataSource bean定义——

<bean id="dataSource"
    class="org.logicalcobwebs.proxool.ProxoolDataSource">
    <property name="driver">
        <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="driverUrl">
        <value>jdbc:mysql://localhost:3306/dbname?user=yourname&amp;password=yourpass</value>
    </property>
    <property name="user" value="yourname" />
    <property name="password" value="yourpass" />
    <property name="alias" value="Pool_dbname" />
    <property name="houseKeepingSleepTime" value="90000" />
    <property name="prototypeCount" value="0" />
    <property name="maximumConnectionCount" value="50" />
    <property name="minimumConnectionCount" value="2" />
    <property name="simultaneousBuildThrottle" value="50" />
    <property name="maximumConnectionLifetime" value="14400000" />
    <property name="houseKeepingTestSql" value="select CURRENT_DATE" />
</bean>

第一种方式需要把用户名和密码写在连接串里面,
ProxoolDataSource类提供的user,password属性似乎没有什么用。
无论提供什么,它都会以空用户名、密码去连接数据库。
这可能是Proxool RC0.93的一个bug。
不过配置中的user,password两个属性还必须设置,否则hibernate会报空指针错误。


其中proxool的配置文件可以采用xmlFile"proxool.xml"或者propertyFile"proxool.properties",放置与applicationContext.xml同目录下:
"proxool.xml"格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<proxool-config>
   <proxool>
      <alias>Pool_dbname</alias>
      <driver-url>jdbc:mysql://localhost:3306/dbname</driver-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <driver-properties>
      <property name="user" value="yourname"/>
      <property name="password" value="yourpass"/>
      </driver-properties>
      <house-keeping-sleep-time>60000</house-keeping-sleep-time>
      <maximum-connection-count>20</maximum-connection-count> 
      <minimum-connection-count>2</minimum-connection-count>
      <prototype-count>0</prototype-count>
      <simultaneous-build-throttle>20</simultaneous-build-throttle>
      <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
      <statistics>15s,10m,1d</statistics>
      <statistics-log-level>INFO</statistics-log-level>
   </proxool>
   <proxool>
    <!--可以配置多个库-->
   </proxool>
</proxool-config>


"proxool.properties"格式如下:
jdbc-0.proxool.alias=Pool_dbname
jdbc-0.proxool.driver-url=jdbc:mysql://localhost:3306/dbname
jdbc-0.proxool.driver-class=com.mysql.jdbc.Driver
jdbc-0.user=yourname
jdbc-0.password=yourpass
jdbc-0.proxool.house-keeping-sleep-time=60000
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE
jdbc-0.proxool.maximum-connection-count=10
jdbc-0.proxool.minimum-connection-count=3
jdbc-0.proxool.maximum-connection-lifetime=18000000
jdbc-0.proxool.prototype-count=3
jdbc-0.proxool.simultaneous-build-throttle=10
jdbc-0.proxool.recently-started-threshold=60000
jdbc-0.proxool.overload-without-refusal-lifetime=50000
jdbc-0.proxool.maximum-active-time=60000
jdbc-0.proxool.verbose=true
jdbc-0.proxool.trace=true
jdbc-0.proxool.fatal-sql-exception=Fatal error

jdbc-2.proxool.alias=Pool_dbname2
……
<!--可以配置多个库-->

你可能感兴趣的:(Hibernate,jdbc)