【问题标题】:Invalid property 'connectionProperties' of bean class [org.apache.commons.dbcp.BasicDataSource]bean 类 [org.apache.commons.dbcp.BasicDataSource] 的无效属性“connectionProperties”
【发布时间】:2014-05-10 09:26:05
【问题描述】:

初始化 BasicDataSource 时出现此异常。我想将自定义连接属性传递给数据源。

我的配置是:

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)

【问题讨论】:

  • 我已经阅读了那篇文章。但是它已经很老了,并且没有可以通过更改 spring 配置来实现的解决方案。

标签: java jdbc apache-commons-dbcp


【解决方案1】:

我使用this post from spring forum 解决了这个问题。

添加这个 bean 解决了我的问题。

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

【讨论】:

    猜你喜欢
    • 2013-12-12
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    • 2015-10-21
    • 1970-01-01
    • 2019-12-01
    相关资源
    最近更新 更多