Invalid property 'connectionProperties' of bean class [org.apache.commons.dbcp.BasicDataSource]

StackOverflow https://stackoverflow.com/questions/23579345

  •  19-07-2023
  •  | 
  •  

Question

I am getting this exception when initializing BasicDataSource. I want to pass Custom connection property to the dataSource.

My config is:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'connectionProperties' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'connectionProperties' 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:1042)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1420)
Was it helpful?

Solution

I used this post from spring forum to resolve the issue.

Adding this bean solved my issue.

<bean
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
    lazy-init="false">
    <property name="targetObject" ref="csdbDataSource" />
    <property name="targetMethod" value="addConnectionProperty" />
    <property name="arguments">
        <list>
            <value>defaultRowPrefetch</value>
            <value>1</value>
        </list>
    </property>
</bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top