在 iBatis 中设置 DBCP 数据源的连接池大小

Set connection pool size for DBCP datasource in iBatis

如何设置 DBCP 数据源的连接池大小?另外,默认的数据源是池化的吗?

我试图设置 maxTotal (http://commons.apache.org/proper/commons-dbcp/configuration.html),但它 returns 一个无效的 属性 错误。

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="${db.driver}"/>
  <property name="url" value="${db.url}"/>
  <property name="username" value="${db.username}"/>
  <property name="password" value="${db.password}"/>
  <property name="poolPreparedStatements" value="false"/>
  <property name="testWhileIdle" value="true"/>
  <property name="testOnBorrow" value="true"/>
  <property name="validationQuery" value="SELECT 1 FROM DUAL"/>     
  <property name="timeBetweenEvictionRunsMillis" value="30000"/>
  <property name="maxTotal" value="1"/>     
</bean>


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class pat
h resource [META-INF/spring/base-gateway.xml]: Error setting property values; nested exception is org.springframework.be
ans.NotWritablePropertyException: Invalid property 'maxTotal' of bean class [org.apache.commons.dbcp.BasicDataSource]: B
ean property 'maxTotal' is not writable or has an invalid setter method. Does the parameter type of the setter match the
 return type of the getter?
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCap
ableBeanFactory.java:1361)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBea
nFactory.java:1086)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBea
nFactory.java:517)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanF
actory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.jav
a:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFac
tory.java:580)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationCo
ntext.java:895)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at sf.av.core.gateway.GenericGateway.main(GenericGateway.java:23)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxTotal' of bean class [org.apache
.commons.dbcp.BasicDataSource]: Bean property 'maxTotal' is not writable or has an invalid setter method. Does the param
eter type of the setter match the return type of the getter?
        at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1024)
        at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:900)
        at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
        at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCap
ableBeanFactory.java:1358)
        ... 13 more 

很可能您正在使用的 DBCP jar 版本与配置文档不匹配,for example

Users should also be aware that some configuration options (e.g. maxActive to maxTotal) have been renamed to align them with the new names used by Commons Pool 2.

您使用的罐子中的 BasicDataSource class 上是否有 maxTotal setter?