|
@@ -0,0 +1,65 @@
|
|
|
+<?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" xmlns:context="http://www.springframework.org/schema/context"
|
|
|
+ xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
|
|
|
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
|
+ classpath:org/springframework/beans/factory/xml/spring-beans-3.1.xsd
|
|
|
+ http://www.springframework.org/schema/aop
|
|
|
+ classpath:org/springframework/aop/config/spring-aop-3.1.xsd
|
|
|
+ http://www.springframework.org/schema/tx
|
|
|
+ classpath:org/springframework/transaction/config/spring-tx-3.1.xsd
|
|
|
+ http://www.springframework.org/schema/context
|
|
|
+ classpath:org/springframework/context/config/spring-context-3.1.xsd
|
|
|
+ ">
|
|
|
+
|
|
|
+ <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="clone">
|
|
|
+
|
|
|
+ <property name="driverClassName" value="${jdbc.driverClassName}" />
|
|
|
+ <property name="url" value="${edu.jdbc.url}" />
|
|
|
+ <property name="username" value="${edu.jdbc.username}" />
|
|
|
+ <property name="password" value="${edu.jdbc.password}" />
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ <property name="initialSize" value="2" />
|
|
|
+
|
|
|
+ <property name="minIdle" value="2" />
|
|
|
+
|
|
|
+ <property name="maxActive" value="10" />
|
|
|
+
|
|
|
+
|
|
|
+ <property name="maxWait" value="60000" />
|
|
|
+
|
|
|
+
|
|
|
+ 有些数据库连接的时候有超时限制(MySQL连接在8小时后断开),或者由于网络中断等原因,连接池的连接会出现失效的情况,这时候可以设置一个testWhileIdle参数为true,
|
|
|
+ 如果检测到当前连接不活跃的时间超过了timeBetweenEvictionRunsMillis,则去手动检测一下当前连接的有效性,在保证确实有效后才加以使用。
|
|
|
+ 在检测活跃性时,如果当前的活跃时间大于minEvictableIdleTimeMillis,则认为需要关闭当前连接。当
|
|
|
+ 然,为了保证绝对的可用性,你也可以使用testOnBorrow为true(即在每次获取Connection对象时都检测其可用性),不过这样会影响性能。
|
|
|
+ -->
|
|
|
+
|
|
|
+ <property name="timeBetweenEvictionRunsMillis" value="3600000" />
|
|
|
+
|
|
|
+ <property name="minEvictableIdleTimeMillis" value="300000" />
|
|
|
+
|
|
|
+ <property name="validationQuery" value="${jdbc.pool.validationQuery}" />
|
|
|
+
|
|
|
+ <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>
|
|
|
+
|
|
|
+
|
|
|
+ <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
|
|
+ <property name="dataSource" ref="dataSource"></property>
|
|
|
+ </bean>
|
|
|
+</beans>
|