在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
我配置了两个数据源,这是其中一个