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&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)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架