how to resolve org.springframework.beans.NotWritablePropertyException
hi i am using spring config.xml to config my embedded database hsqldb. my spring config is as below:
<jdbc:embedded-databas开发者_StackOverflow中文版e id="dataSource" type="HSQL">
<jdbc:script location="classpath:schema.sql" />
</jdbc:embedded-database>
<bean id="adapterDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="datasource" ref="dataSource"></property>
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:data/db/lmexadapter_db" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
when run run my appication which is using above spring config.xml it give me a exception as below:
org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'datasource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
please help to resolve this as soon as possible
Thank you
The issue is that org.apache.commons.dbcp.BasicDataSource doesn't have a "setDatasource" method. It does have a protected field "datasource", however, which you could expose by subclassing and providing a setter.
精彩评论