如何设置DBCP数据源的连接池大小?此外,是否默认数据源?
我尝试设置maxTotal
(http://commons.apache.org/proper/commons-dbcp/configuration.html),但它返回了无效的属性错误。
<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
答案 0 :(得分:1)
您使用的DBCP jar版本与配置文档for example之间很可能不匹配:
用户还应该知道某些配置选项(例如maxActive到maxTotal)已重命名,以使它们与Commons Pool 2使用的新名称对齐。
您使用的jar中的BasicDataSource
类是否具有maxTotal
setter?