今天在网上无意间看到了Druid连接池(),正好闲来无事,在我们项目中配置了一下,特此记录一下。 我们项目用的SSH框架,数据库是Oracle,使用的是proxool连接池,所以改成druid还是很简单的。
-
首先下载druid的jar包,我用的是0.2.9
-
在src下添加druid.properties,内容如下: url:jdbc:oracle:thin:@localhost:1521:orcl driverClassName:oracle.jdbc.driver.OracleDriver username:username password:password
filters:stat maxActive:20 initialSize:1 maxWait:60000 minIdle:10 timeBetweenEvictionRunsMillis:60000 minEvictableIdleTimeMillis:300000 validationQuery:SELECT 'x' testWhileIdle:true testOnBorrow:false testOnReturn:false poolPreparedStatements:true maxOpenPreparedStatements:20 removeAbandoned:true removeAbandonedTimeout:1800 logAbandoned:true -
编辑Spring的配置文件applicationContext.xml,修改连接池为druid。首先通过spring加载druid.properties,然后修改连接池: <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations"> <list> <value>/WEB-INF/classes/druid.properties</value> </list> </property> </bean> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="driverClassName" value="${driverClassName}" /> <property name="filters" value="${filters}" /></bean>