How can one set the connection pool size for a DBCP datasource? Also, is the default datasource pooled?
I tried to set maxTotal
(http://commons.apache.org/proper/commons-dbcp/configuration.html), but it returns an invalid property error.
<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$1.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
You most likely have a mismatch between the version of the DBCP jar you are using and the configuration documentation, 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.
Does the BasicDataSource
class from the jar you are using have the maxTotal
setter on it or not?