palkars
palkars

Reputation: 502

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

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)

Upvotes: 1

Views: 3164

Answers (1)

palkars
palkars

Reputation: 502

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>

Upvotes: 1

Related Questions