首页 > 代码库 > Spring整合数据源Druid

Spring整合数据源Druid

正式版本下载:
maven中央仓库: http://central.maven.org/maven2/com/alibaba/druid/ 
Alibaba开源下载: http://code.alibabatech.com/mvn/releases/com/alibaba/druid/

GitHub地址:https://github.com/alibaba/druid/

web.xml配置:

<filter>        <filter-name>DruidWebStatFilter</filter-name>        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>        <init-param>            <param-name>exclusions</param-name>            <param-value>/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>        </init-param></filter><servlet>        <servlet-name>DruidStatView</servlet-name>        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class></servlet><servlet-mapping>        <servlet-name>DruidStatView</servlet-name>        <url-pattern>/druid/*</url-pattern></servlet-mapping>

spring.xml配置:

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">        <property name="driverClassName" value="${driverClassName}" />             <!-- 基本属性 url、user、password -->        <property name="url" value="${dbUrl}"/>        <property name="username" value="${dbName}" />        <property name="password" value="${dbPassword}" />             <!-- 配置初始化大小、最小、最大 -->        <property name="initialSize" value="${initialSize}" />        <property name="minIdle" value="${minIdle}" />        <property name="maxActive" value="${maxActive}" />             <!-- 配置获取连接等待超时的时间 -->        <property name="maxWait" value="60000" />             <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->        <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" />         <!-- 配置监控统计拦截的filters -->        <property name="filters" value="stat" /></bean>

 

Spring整合数据源Druid