Skip to content

DBCP迁移

crane-yuan edited this page Apr 5, 2017 · 2 revisions

DruidDataSource的配置是兼容DBCP的。从DBCP迁移到DruidDataSource,只需要修改数据源的实现类就可以了。

DBCP的数据库连接池的实现是:

org.apache.commons.dbcp.BasicDataSource

替换为:

com.alibaba.druid.pool.DruidDataSource

如果需要使用Druid的其他配置,可以参考 https://github.com/alibaba/druid/wiki/配置_DruidDataSource参考配置

例子

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> 
    <property name="url" value="${jdbc_url}" />
    <property name="username" value="${jdbc_user}" />
    <property name="password" value="${jdbc_password}" />
         
    <property name="filters" value="stat" />
 
    <property name="maxActive" value="20" />
    <property name="initialSize" value="1" />
    <property name="maxWait" value="60000" />
    <property name="minIdle" value="1" />
 
    <property name="timeBetweenEvictionRunsMillis" value="60000" />
    <property name="minEvictableIdleTimeMillis" value="300000" />
 
    <property name="validationQuery" value="SELECT 'x'" />
    <property name="testWhileIdle" value="true" />
    <property name="testOnBorrow" value="false" />
    <property name="testOnReturn" value="false" />
    <property name="poolPreparedStatements" value="true" />
    <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
</bean>
Clone this wiki locally