Skip to content

DruidDataSource配置

yunnysunny edited this page Mar 29, 2013 · 23 revisions

DruidDataSource大部分属性都是参考DBCP的,如果你原来就是使用DBCP,迁移是十分方便的。

 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> 
     <property name="url" value="${jdbc_url}" />
     <property name="username"><value>${jdbc_user}</value></property>
     <property name="password" value="${jdbc_password}" />
      
     <property name="filters"><value>stat</value></property>
  
     <property name="maxActive"><value>20</value></property>
     <property name="initialSize"><value>1</value></property>
     <property name="maxWait"><value>60000</value></property>
     <property name="minIdle"><value>1</value></property>

     <property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
     <property name="minEvictableIdleTimeMillis"><value>300000</value></property>

     <property name="validationQuery"><value>SELECT 'x'</value></property>
     <property name="testWhileIdle"><value>true</value></property>
     <property name="testOnBorrow"><value>false</value></property>
     <property name="testOnReturn"><value>false</value></property>
      
     <property name="poolPreparedStatements"><value>true</value></property>
     <property name="maxOpenPreparedStatements"><value>20</value></property>
 </bean>

在上面的配置中,通常你需要配置url、username、password,maxActive这三项。

Clone this wiki locally