Spring整合BoneCP+Hibernate配置数据连接池

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="hibernateProperties">
                        <props>
                        <!--如果用的是Hibernate3--> 
                     <prop key="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</prop>
                    
                    <!--如果用的是Hibernate4 
              <prop key="hibernate.service.jdbc.connections.spi.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</prop>
                    -->
                    <prop key="hibernate.connection.driver_class">${driverClass}</prop>
                    <prop key="hibernate.connection.url">${jdbcUrl}</prop>
                    <prop key="hibernate.connection.username">${username}</prop>
                    <prop key="hibernate.connection.password">${password}</prop>
                    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                    <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                    <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
                    <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
                    <!--
                    <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
                    -->
                    <prop key="bonecp.idleMaxAge">${idleMaxAge}</prop>
                    <prop key="bonecp.idleConnectionTestPeriod">${idleConnectionTestPeriod}</prop>
                    <prop key="bonecp.partitionCount">${partitionCount}</prop>
                    <prop key="bonecp.acquireIncrement">${acquireIncrement}</prop>
                    <prop key="bonecp.maxConnectionsPerPartition">${maxConnectionsPerPartition}</prop>
                    <prop key="bonecp.minConnectionsPerPartition">${minConnectionsPerPartition}</prop>
                    <prop key="bonecp.statementsCacheSize">${statementsCacheSize}</prop>
                    
                    <prop key="bonecp.releaseHelperThreads">${releaseHelperThreads}</prop>
                    </props>
            </property>
                <property name="mappingDirectoryLocations">
                <list>
                    <value>WEB-INF/conf/hibernate</value>
                </list>
            </property>
    </bean>

 properties配置文件

# 数据库连接驱动
driverClass=com.mysql.jdbc.Driver
#  数据库路径
jdbcUrl=jdbc:mysql://127.0.0.1:3306/gameserver?useUnicode=true&amp;characterEncoding=UTF-8
#  数据库用户名
username=root
#  数据库密码
password=root
#  检查数据库连接池中空闲连接的间隔时间
idleConnectionTestPeriod=60
#  连接池中未使用的链接最大存活时间
idleMaxAge=240
#  设置每个分区含有connection最大个数
maxConnectionsPerPartition=60
#  设置每个分区含有connection最小个数
minConnectionsPerPartition=20
#  设置每个分区数
partitionCount=3
#  设置分区中的connection增长数量
acquireIncrement=5
#  设置连接池阀值
poolAvailabilityThreshold=10
#  连接时间
connectionTimeout=3000
# 每个分区释放链接助理进程的数量,默认值:3,除非你的一个数据库连接的时间内做了很多工作,不然过多的助理进程会影响你的性能 -->  
releaseHelperThreads=3
# 缓存prepared statements的大小,默认值:0 
statementsCacheSize=30
# hibernate配置方法
hibernate.hbm2ddl.auto=true
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.ehcache_config_file=/ehcache/ehcache-hibernate-local.xml
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider

(作者:LeeHonGee)

原文地址:https://www.cnblogs.com/leehongee/p/3016451.html