在spring下配置連結池
DBCP
<!--bean id="fidsDatasource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${db.driverClassName}</value>
</property>
<property name="url">
<value>${db.url}</value>
</property>
<property name="username">
<value>${db.username}</value>
</property>
<property name="password">
<value>${db.password}</value>
</property>
<property name="maxActive">
<value>25</value>
</property>
<property name="maxWait">
<value>10000</value>
</property>
<property name="maxIdle">
<value>10</value>
</property>
</bean-->
C3P0
<!--bean id="fidsDatasource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass">
<value>${db.driverClass}</value>
</property>
<property name="jdbcUrl">
<value>${db.jdbcurl}</value>
</property>
<property name="user">
<value>${db.user}</value>
</property>
<property name="password">
<value>${db.password}</value>
</property>
<property name="minPoolSize">
<value>15</value>
</property>
<property name="acquireIncrement">
<value>10000</value>
</property>
<property name="maxPoolSize">
<value>25</value>
</property>
</bean-->
- DBCP object created 2006-10-25 09:08:02 by the following code was never closed:
- java.lang.Exception
- at org.apache.commons.dbcp.AbandonedTrace.setStackTrace(AbandonedTrace.java:157)
- at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:76)
- at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
- at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
- at org.apache.commons.dbcp.BasicDataSource$$FastClassByCGLIB$$de03396c.invoke(<generated>)
- at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
DBCP object created 2006-10-25 09:08:02 by the following code was never closed:
java.lang.Exception
at org.apache.commons.dbcp.AbandonedTrace.setStackTrace(AbandonedTrace.java:157)
at org.apache.commons.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:76)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at org.apache.commons.dbcp.BasicDataSource$$FastClassByCGLIB$$de03396c.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
上面的錯誤,每一連接會連續打出三次一樣的,
下面是我的配置
<!-- 10000號數據源 -->
- <bean id="dispatchdataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="${dipatch.jdbc.driverClassName}" />
- <property name="url" value="${dipatch.jdbc.url}" />
- <property name="username" value="${dipatch.jdbc.username}" />
- <property name="password" value="${dipatch.jdbc.password}" />
- <property name="maxActive" value="${dipatch.jdbc.maxActive}" />
- <property name="maxIdle" value="${dipatch.jdbc.maxIdle}" />
- <property name="maxWait" value="${dipatch.jdbc.maxWait}" />
- <property name="defaultAutoCommit" value="${dipatch.jdbc.defaultAutoCommit}"/>
- <property name="removeAbandoned" value="${dipatch.jdbc.removeAbandoned}"/>
- <property name="removeAbandonedTimeout" value="${dipatch.jdbc.removeAbandonedTimeout}"/>
- <property name="logAbandoned" value="${dipatch.jdbc.logAbandoned}"/>
- </bean>
<bean id="dispatchdataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${dipatch.jdbc.driverClassName}" />
<property name="url" value="${dipatch.jdbc.url}" />
<property name="username" value="${dipatch.jdbc.username}" />
<property name="password" value="${dipatch.jdbc.password}" />
<property name="maxActive" value="${dipatch.jdbc.maxActive}" />
<property name="maxIdle" value="${dipatch.jdbc.maxIdle}" />
<property name="maxWait" value="${dipatch.jdbc.maxWait}" />
<property name="defaultAutoCommit" value="${dipatch.jdbc.defaultAutoCommit}"/>
<property name="removeAbandoned" value="${dipatch.jdbc.removeAbandoned}"/>
<property name="removeAbandonedTimeout" value="${dipatch.jdbc.removeAbandonedTimeout}"/>
<property name="logAbandoned" value="${dipatch.jdbc.logAbandoned}"/>
</bean>
對應的
- #10000號數據源的配置
- dipatch.jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
- dipatch.jdbc.url=jdbc:oracle:thin:@192.168.20.196:1521:ahres
- dipatch.jdbc.username=bpbj
- dipatch.jdbc.password=bpbj
- #連接池的最大數據庫連接數,設為0表示無限制。
- dipatch.jdbc.maxActive=40
- #數據庫連接的最大空閑時間。超過此空閑時間,數據庫連接將被標記為不可用,然后被釋放。設為0表示無限制。
- dipatch.jdbc.maxIdle=30
- #最大建立連接等待時間。如果超過此時間將接到異常。設為-1表示無限制。
- dipatch.jdbc.maxWait=10000
- dipatch.jdbc.defaultAutoCommit=true
- #回收被遺棄的(一般是忘了釋放的)數據庫連接到連接池中。
- dipatch.jdbc.removeAbandoned=true
- # 數據庫連接過多長時間不用將被視為被遺棄而收回連接池中。
- dipatch.jdbc.removeAbandonedTimeout=30
- # 將被遺棄的數據庫連接的回收記入日志。
- dipatch.jdbc.logAbandoned=true
#10000號數據源的配置
dipatch.jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
dipatch.jdbc.url=jdbc:oracle:thin:@192.168.20.196:1521:ahres
dipatch.jdbc.username=bpbj
dipatch.jdbc.password=bpbj
#連接池的最大數據庫連接數,設為0表示無限制。
dipatch.jdbc.maxActive=40
#數據庫連接的最大空閑時間。超過此空閑時間,數據庫連接將被標記為不可用,然后被釋放。設為0表示無限制。
dipatch.jdbc.maxIdle=30
#最大建立連接等待時間。如果超過此時間將接到異常。設為-1表示無限制。
dipatch.jdbc.maxWait=10000
dipatch.jdbc.defaultAutoCommit=true
#回收被遺棄的(一般是忘了釋放的)數據庫連接到連接池中。
dipatch.jdbc.removeAbandoned=true
# 數據庫連接過多長時間不用將被視為被遺棄而收回連接池中。
dipatch.jdbc.removeAbandonedTimeout=30
# 將被遺棄的數據庫連接的回收記入日志。
dipatch.jdbc.logAbandoned=true
我配置了兩個數據源,這是其中一個