spring整合常用连接池

一  整合阿里巴巴Druid

测试环境:  mysql5.5      druid-1.0.9.jar

编写druid.properties

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/studentdb
theUser=root
password=test123
#配置监控统计拦截的filters,去掉后监控界面sql无法统计
filters=stat
#配置初始化大小 
initialSize=6
#配置初始化最大连接数 
maxActive=20
#配置初始化最小连接数 
minIdle=3
#配置获取连接等待超时的时间,1分钟 
maxWait=60000
#检测连接是否有效的SQL 
validationQuery=SELECT 'x'
#空闲的连接是否进行有效性检查
testWhileIdle=true
#申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能 
testOnBorrow=false
#归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能 
testOnReturn=false
#启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true 
maxPoolPreparedStatementPerConnectionSize=20
#对于长时间不使用的连接强制关闭 
removeAbandoned=true
#超过60秒的空闲连接就可以被关闭了,单位是秒 
removeAbandonedTimeout=60
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 
timeBetweenEvictionRunsMillis=10000
#配置一个连接在池中最小生存的时间,单位是毫秒 
minEvictableIdleTimeMillis=30000

在spring中集成

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	                    http://www.springframework.org/schema/aop
	                    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
	                    http://www.springframework.org/schema/tx
	                    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
	<!-- 导入其它sping配置文件 -->
	<import resource="classpath:configs/spring/context-*.xml"/>
	<!-- durid连接池配置start -->
	<bean id="duridConfig" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
		<property name="locations">
		    <list>
				<value>classpath:configs/druid.properties</value>
			</list>
		</property>
    </bean>
   <!--druid数据源-->
    <bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource" 
		init-method="init" destroy-method="close">
		<property name="driverClassName" value="${driverClassName}" />
		<property name="url" value="${url}" />
		<property name="username" value="${theUser}" />
		<property name="password" value="${password}" />
		<property name="filters" value="${filters}" />
		<property name="initialSize" value="${initialSize}" />
		<property name="maxActive" value="${maxActive}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

御前两把刀刀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值