Announcement Announcement Module
Collapse
No announcement yet.
junit problem with commons dbcp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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.

      Comment


      • #4
        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

        Comment


        • #5
          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...

          Comment


          • #6
            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!

            Comment

            Working...
            X