This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

junit problem with commons dbcp

When I run my junit test against my DAOs, I get a weird Commons DBCP Exception complaining about the initialiSize for the data source could not be set.

however, when I run the app from tomcat, the data source loads fine.

here's the stack trace

Code:

junit.framework.AssertionFailedError&#58; Exception in constructor&#58; testGetCampaign &#40;org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'realDataSource' defined in class path resource &#91;web/WEB-INF/dataAccessContext.xml&#93;&#58; Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException&#58; Invalid property 'initialSize' of bean class &#91;org.apache.commons.dbcp.BasicDataSource&#93;&#58; Bean property 'initialSize' is not writable or has an invalid setter method&#58; Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.NotWritablePropertyException&#58; Invalid property 'initialSize' of bean class &#91;org.apache.commons.dbcp.BasicDataSource&#93;&#58; Bean property 'initialSize' is not writable or has an invalid setter method&#58; Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;796&#41;
at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;716&#41;
at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;844&#41;
at org.springframework.beans.BeanWrapperImpl.setPropertyValues&#40;BeanWrapperImpl.java&#58;871&#41;
at org.springframework.beans.BeanWrapperImpl.setPropertyValues&#40;BeanWrapperImpl.java&#58;860&#41;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;926&#41;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;727&#41;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;336&#41;
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;277&#41;
at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;312&#41;
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;80&#41;
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;65&#41;
....

Also here's my dataAccess.xml

Code:

<bean id="realDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>$&#123;emod.jdbc.driverClassName&#125;</value>
</property>
<property name="url">
<value>$&#123;emod.jdbc.url&#125;</value>
</property>
<property name="username">
<value>$&#123;emod.jdbc.username&#125;</value>
</property>
<property name="password">
<value>$&#123;emod.jdbc.password&#125;</value>
</property>
<!--
- The initial number of connections that are created when the pool is started.
-->
<property name="initialSize">
<value>$&#123;emod.jdbc.datasource.initialSize&#125;</value>
</property>
<!--
- The maximum number of active connections that can be allocated from
- this pool at the same time, or zero for no limit.
-->
<property name="maxActive">
<value>$&#123;emod.jdbc.datasource.maxActive&#125;</value>
</property>
<!--
- The maximum number of active connections that can remain idle in the
- pool, without extra ones being released, or zero for no limit.
-->
<property name="maxIdle">
<value>$&#123;emod.jdbc.datasource.maxIdle&#125;</value>
</property>
<!--
- The maximum number of milliseconds that the pool will wait
- &#40;when there are no available connections&#41; for a connection to be
- returned before throwing an exception, or -1 to wait indefinitely.
-->
<property name="maxWait">
<value>$&#123;emod.jdbc.datasource.maxWait&#125;</value>
</property>
<!--
- Enable prepared statement pooling for this pool. Default is false
-->
<property name="poolPreparedStatements">
<value>$&#123;emod.jdbc.datasource.poolPreparedStatements&#125;</value>
</property>
</bean>

the junit and tomcat app both read this same file, yet in the junit case it throws that above exception.. any ideas why?

Comment

my applicationContext.xml has the propertyConfigurator to load the values that emod.jdbc.datasource.xxx evaluates to. (both applicationContext.xml and dataAccessContext.xml are loaded via classpath in junit and normal tomcat deployment)

even setting the actual values in the dataAccess.xml instead of the ${} gives me the error.