Results 1 to 6 of 6

Thread: junit problem with commons dbcp

  1. #1
    Join Date
    Jun 2005
    Location
    San Mateo, CA
    Posts
    34

    Default 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: Exception in constructor: testGetCampaign (org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'realDataSource' defined in class path resource [web/WEB-INF/dataAccessContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'initialSize' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'initialSize' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    org.springframework.beans.NotWritablePropertyException: Invalid property 'initialSize' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'initialSize' 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.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:796)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:716)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:844)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:871)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:860)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:926)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:727)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:336)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:223)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:277)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:312)
    	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?

    thanks

  2. #2
    Join Date
    Sep 2005
    Location
    Vienna
    Posts
    44

    Default

    Hi,

    From what I see - and the similar errors I had in the past - I would expect that in the context of your unit tests ${emod.jdbc.datasource.initialSize} does not resolve to an int.

    As I don't see how you resolve the $ variables in dataAccess.xml I can only imagine that the property file you use is not on the classpath in your unit tests.

    Erik

  3. #3
    Join Date
    Jun 2005
    Location
    San Mateo, CA
    Posts
    34

    Default

    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.

  4. #4
    Join Date
    Sep 2005
    Location
    Vienna
    Posts
    44

    Default

    Hi,

    The only other idea I have left is that you have an older version of DBCP on your classpath in your unit test environment - initialSize was introduced with DBCP 1.2.

    If you have 1.1 (or older), initialSize will not be found and this would cause the error.

    Erik

  5. #5

    Default

    Quote Originally Posted by ErikFK
    Hi,

    The only other idea I have left is that you have an older version of DBCP on your classpath in your unit test environment - initialSize was introduced with DBCP 1.2.

    If you have 1.1 (or older), initialSize will not be found and this would cause the error.

    Erik
    or maybe your propertyplaceholder is not configured properly...

  6. #6
    Join Date
    Jun 2005
    Location
    San Mateo, CA
    Posts
    34

    Default Thanks for your help!

    Hi,

    The only other idea I have left is that you have an older version of DBCP on your classpath in your unit test environment - initialSize was introduced with DBCP 1.2.

    If you have 1.1 (or older), initialSize will not be found and this would cause the error.

    Erik
    Perfect, that was it! In my eclipse environment, I was depending on another project that had the older 1.1 dbcp!

    Thanks for helping on this!

Similar Threads

  1. Replies: 13
    Last Post: Feb 5th, 2010, 12:31 AM
  2. Log4j, Commons Logging in JRun 4 problem
    By virgo_ct in forum Container
    Replies: 4
    Last Post: Jul 13th, 2005, 04:17 AM
  3. Replies: 1
    Last Post: Jul 12th, 2005, 06:11 AM
  4. Replies: 1
    Last Post: Jul 5th, 2005, 03:48 AM
  5. Lazy Load Problem when Doing UnitTest
    By yoshi in forum Data
    Replies: 7
    Last Post: Sep 29th, 2004, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •