commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mubasher Usman (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DBCP-473) Datasource bean creation failed due to mismatched return type of setter and getter for connectionInitSqls in BasicDataSource
Date Wed, 16 Nov 2016 20:20:58 GMT

     [ https://issues.apache.org/jira/browse/DBCP-473?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Mubasher Usman updated DBCP-473:
--------------------------------
       Priority: Critical  (was: Major)
    Description: 
{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} 

  was:
While creating bean i faced exception 
"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?"

Here is my bean configuration

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
		destroy-method="close" lazy-init="true">
		<!-- REF: http://commons.apache.org/proper/commons-dbcp/configuration.html -->
		<property name="driverClassName" value="#{jdbc.driverClassName}" />
		<property name="url" value="#{jdbc.url}" />
		<property name="username" value="#{jdbc.username}" />
		<property name="password" value="#{jdbc.password}" />
		<property name="defaultAutoCommit" value="#jdbc.defaultAutoCommit}" />
		<property name="connectionInitSqls">
			<list>
				<value>ALTER SESSION SET * NLS_SORT=XCYECH</value>
			</list>
		</property>
</bean>

     Issue Type: Improvement  (was: Bug)
        Summary: Datasource bean creation failed due to mismatched return type of setter and
getter for connectionInitSqls in BasicDataSource  (was: Datasource bean creation faild due
to mismatched return type of setter and getter of connectionInitSqls in BasicDataSource)

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

Mime
View raw message