gpt4 book ai didi

java - bean 类 [org.apache.commons.dbcp.BasicDataSource] 的属性 'connectionProperties' 无效

转载 作者:行者123 更新时间:2023-12-01 13:00:00 25 4
gpt4 key购买 nike

我在初始化 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)

最佳答案

我用了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>

关于java - bean 类 [org.apache.commons.dbcp.BasicDataSource] 的属性 'connectionProperties' 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23579345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com