[ https://issues.apache.org/jira/browse/DBCP-473?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mubasher Usman updated DBCP-473: -------------------------------- Flags: Important Labels: easyfix (was: ) Fix Version/s: 2.2 > Datasource bean creation failed due to mismatched return type of setter and > getter for connectionInitSqls in BasicDataSource > ---------------------------------------------------------------------------------------------------------------------------- > > Key: DBCP-473 > URL: https://issues.apache.org/jira/browse/DBCP-473 > Project: Commons Dbcp > Issue Type: Improvement > Affects Versions: 2.1.1 > Environment: Tomcat > java 7 update 70 > spring 2.5 > Reporter: Mubasher Usman > Priority: Critical > Labels: easyfix > Fix For: 2.2 > > > {panel:title=Description|titleBGColor=#8DB|bgColor=#AAA} > The issue is that while Spring Starts bean creation of datasource, It throws > exception org.springframework.beans.NotWritablePropertyException. And > complains that Invalid property 'connectionInitSqls' of bean class > [org.apache.commons.dbcp2.BasicDataSource]: Bean property > 'connectionInitSqls' is not writable or has an invalid setter method. Does > the parameter type of the setter match the return type of the getter? > {panel} > {panel:title=Steps To Reproduce|titleBGColor=#8DB|bgColor=#AAA} > Here is My bean configuration in Spring's XML config file. > {code:title=applicationContext-datasource.xml} > <bean id="fileStore_dataSource" > class="org.apache.commons.dbcp2.BasicDataSource" > destroy-method="close" lazy-init="true"> > <!-- Just that property which causes problem --> > <property name="connectionInitSqls"> > <list> > <value>#{filestore.jdbc.connectionInitSql}</value> > </list> > </property> > </bean> > {code} > Here is the Code from DBCP2 version 2.1.1 > {code:title=BasicDataSource.java} > private volatile List<String> connectionInitSqls; > public List<String> getConnectionInitSqls() { > final List<String> result = connectionInitSqls; > if (result == null) { > return Collections.emptyList(); > } > return result; > } > public void setConnectionInitSqls(final Collection<String> > connectionInitSqls) { > if (connectionInitSqls != null && connectionInitSqls.size() > 0) { > ArrayList<String> newVal = null; > for (final String s : connectionInitSqls) { > if (s != null && s.trim().length() > 0) { > if (newVal == null) { > newVal = new ArrayList<>(); > } > newVal.add(s); > } > } > this.connectionInitSqls = newVal; > } else { > this.connectionInitSqls = null; > } > } > {code} > {panel} > {panel:title=Improvements/sugestions|titleBGColor=#AD3|bgColor=#AAA} > There should be a new setter method for connectionInitSqls which accept > List<E> Type argument. > {panel} > {panel:title=Notes|titleBGColor=#3AF|bgColor=#AAA} > There is a good discussion on this issue on Stackoverflow. > http://stackoverflow.com/questions/40636372/spring-bean-creation-failed-can-parameter-type-of-the-setter-be-parent-of-the-r/40637584?noredirect=1#comment68514083_40637584 > {panel} -- This message was sent by Atlassian JIRA (v6.3.4#6332)